如题
系统是linux+apache

解决方案 »

  1.   


    $str='abcd';
    if(fie_put_contents("/test/test.php",$str)){
          echo '有写权限';
    }else{
          echo '没有写权限';
    }
      

  2.   

    楼上的兄弟,这过于简单了吧。。function file_mode_info($file_path)
    {
        /* 如果不存在,则不可读、不可写、不可改 */
        if (!file_exists($file_path))
        {
            return false;
        }
        $ = 0;
        if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
        {
            /* 测试文件 */
            $test_file = $file_path . '/cf_test.txt';
            /* 如果是目录 */
            if (is_dir($file_path))
            {
                /* 检查目录是否可读 */
                $dir = @opendir($file_path);
                if ($dir === false)
                {
                    return $; //如果目录打开失败,直接返回目录不可修改、不可写、不可读
                }
                if (@readdir($dir) !== false)
                {
                    $ ^= 1; //目录可读 001,目录不可读 000
                }
                @closedir($dir);
                /* 检查目录是否可写 */
                $fp = @fopen($test_file, 'wb');
                if ($fp === false)
                {
                    return $; //如果目录中的文件创建失败,返回不可写。
                }
                if (@fwrite($fp, 'directory access testing.') !== false)
                {
                    $ ^= 2; //目录可写可读011,目录可写不可读 010
                }
                @fclose($fp);
                @unlink($test_file);
                /* 检查目录是否可修改 */
                $fp = @fopen($test_file, 'ab+');
                if ($fp === false)
                {
                    return $;
                }
                if (@fwrite($fp, "modify test.\r\n") !== false)
                {
                    $ ^= 4;
                }
                @fclose($fp);
                /* 检查目录下是否有执行rename()函数的权限 */
                if (@rename($test_file, $test_file) !== false)
                {
                    $ ^= 8;
                }
                @unlink($test_file);
            }
            /* 如果是文件 */
            elseif (is_file($file_path))
            {
                /* 以读方式打开 */
                $fp = @fopen($file_path, 'rb');
                if ($fp)
                {
                    $ ^= 1; //可读 001
                }
                @fclose($fp);
                /* 试着修改文件 */
                $fp = @fopen($file_path, 'ab+');
                if ($fp && @fwrite($fp, '') !== false)
                {
                    $ ^= 6; //可修改可写可读 111,不可修改可写可读011...
                }
                @fclose($fp);
                /* 检查目录下是否有执行rename()函数的权限 */
                if (@rename($test_file, $test_file) !== false)
                {
                    $ ^= 8;
                }
            }
        }
        else
        {
            if (@is_readable($file_path))
            {
                $ ^= 1;
            }
            if (@is_writable($file_path))
            {
                $ ^= 14;
            }
        }
        return $;
    }
    请问你们熟悉这个函数么?网上找的,返回值的意义是什么