请问php怎么检查某个文件夹下是否有可写权限 如题系统是linux+apache 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $str='abcd';if(fie_put_contents("/test/test.php",$str)){ echo '有写权限';}else{ echo '没有写权限';} 楼上的兄弟,这过于简单了吧。。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 $;}请问你们熟悉这个函数么?网上找的,返回值的意义是什么 会员表和后台管理表是分开还是合并? 二维数组问题 php如何把别人网站的图片复制到自己网站? 用单选提交后返回页面,页面的单选选项就没了,点一下就刷新怎么解决呢? 为什么在不同的公司注册域名价格会有差别??? 关于preg_replace非常不解的事情? 【求助】一个查询的代码 PHP建立了一个Class后,怎样手动删除这个class 救命,谁能教教我用odbc联接SQl server的分页的方法 如何获取coolies已设置的值??? php生成100个随机数并显示到网页后,怎么生成excel? 对PHP5的反射有了解的请指点迷津
$str='abcd';
if(fie_put_contents("/test/test.php",$str)){
echo '有写权限';
}else{
echo '没有写权限';
}
{
/* 如果不存在,则不可读、不可写、不可改 */
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 $;
}
请问你们熟悉这个函数么?网上找的,返回值的意义是什么