PHP,部分xp机器不能创建文件,不知道是什么原因? 可能有的xp分区是ntfs分区,权限有限 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那你不是地球人,赶紧回火星吧/** * 文件或目录权限检查函数 * * @access public * @param string $file_path 文件路径 * @param bool $rename_prv 是否在检查修改权限时检查执行rename()函数的权限 * * @return int 返回值的取值范围为{0 <= x <= 15},每个值表示的含义可由四位二进制数组合推出。 * 返回值在二进制计数法中,四位由高到低分别代表 * 可执行rename()函数权限、可对文件追加内容权限、可写入文件权限、可读取文件权限。 */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 $;} <?phpecho "[".file_mode_info(getcwd())."]<br>";echo "before exit";exit;echo "after exit";function file_mode_info($file_path){ echo $file_path; echo "<br>"; echo "step 01<br>"; /* 如果不存在,则不可读、不可写、不可改 */ if (!file_exists($file_path)) { return false; } echo "step 02<br>"; $ = 0; if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { echo "step 0301<br>"; /* 测试文件 */ $test_file = $file_path . '/cf_test.txt'; /* 如果是目录 */ if (is_dir($file_path)) { echo "step 0302<br>"; /* 检查目录是否可读 */ $dir = @opendir($file_path); if ($dir === false) { echo "step 0303<br>"; return $; //如果目录打开失败,直接返回目录不可修改、不可写、不可读 } if (@readdir($dir) !== false) { echo "step 0304<br>"; $ ^= 1; //目录可读 001,目录不可读 000 } @closedir($dir); /* 检查目录是否可写 */ $fp = @fopen($test_file, 'wb'); if ($fp === false) { echo "step 0305<br>"; return $; //如果目录中的文件创建失败,返回不可写。 } if (@fwrite($fp, 'directory access testing.') !== false) { echo "step 0306<br>"; $ ^= 2; //目录可写可读011,目录可写不可读 010 } @fclose($fp); @unlink($test_file); /* 检查目录是否可修改 */ $fp = @fopen($test_file, 'ab+'); if ($fp === false) { echo "step 0307<br>"; return $; } if (@fwrite($fp, "modify test.\r\n") !== false) { echo "step 0308<br>"; $ ^= 4; } @fclose($fp); /* 检查目录下是否有执行rename()函数的权限 */ if (@rename($test_file, $test_file) !== false) { echo "step 0309<br>"; $ ^= 8; } @unlink($test_file); } /* 如果是文件 */ elseif (is_file($file_path)) { echo "step 0310<br>"; /* 以读方式打开 */ $fp = @fopen($file_path, 'rb'); if ($fp) { echo "step 0311<br>"; $ ^= 1; //可读 001 } @fclose($fp); /* 试着修改文件 */ $fp = @fopen($file_path, 'ab+'); if ($fp && @fwrite($fp, '') !== false) { echo "step 0312<br>"; $ ^= 6; //可修改可写可读 111,不可修改可写可读011... } @fclose($fp); /* 检查目录下是否有执行rename()函数的权限 */ if (@rename($test_file, $test_file) !== false) { echo "step 0313<br>"; $ ^= 8; } } } else { echo "step 0390<br>"; if (@is_readable($file_path)) { echo "step 0391<br>"; $ ^= 1; } if (@is_writable($file_path)) { echo "step 0392<br>"; $ ^= 14; } } echo "step 04<br>"; return $;}?>我将4楼的程序添加几个标签,在成功的机器上运行的结果是:d:\inetpub\wwwrootstep 01step 02step 0301step 0302step 0304step 0306step 0308step 0309step 04[15]before exit include能否传值 $cryptkey = $keya.md5($keya.$keyc);什么意思 php缓存 form中的input名称中带有小点,php取不到有什么办法吗? orcal怎样设置局域网连接? 缩短用户名的长度,有什么问题吗? asp中的CStr()在PHP中有对应的函数吗? WEB-FAX 网上传真 php怎样读取url的参数? CGI与后来的PHP,JSP,ASP相比,优点和缺点是什么? 用GD库ImageTTFText生成图片,什么中文字体是单一颜色 php 初级小提问
* 文件或目录权限检查函数
*
* @access public
* @param string $file_path 文件路径
* @param bool $rename_prv 是否在检查修改权限时检查执行rename()函数的权限
*
* @return int 返回值的取值范围为{0 <= x <= 15},每个值表示的含义可由四位二进制数组合推出。
* 返回值在二进制计数法中,四位由高到低分别代表
* 可执行rename()函数权限、可对文件追加内容权限、可写入文件权限、可读取文件权限。
*/
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 $;
}
exit;
echo "after exit";function file_mode_info($file_path)
{
echo $file_path;
echo "<br>";
echo "step 01<br>";
/* 如果不存在,则不可读、不可写、不可改 */
if (!file_exists($file_path))
{
return false;
}
echo "step 02<br>";
$ = 0;
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
{
echo "step 0301<br>";
/* 测试文件 */
$test_file = $file_path . '/cf_test.txt';
/* 如果是目录 */
if (is_dir($file_path))
{
echo "step 0302<br>";
/* 检查目录是否可读 */
$dir = @opendir($file_path);
if ($dir === false)
{
echo "step 0303<br>";
return $; //如果目录打开失败,直接返回目录不可修改、不可写、不可读
}
if (@readdir($dir) !== false)
{
echo "step 0304<br>";
$ ^= 1; //目录可读 001,目录不可读 000
}
@closedir($dir);
/* 检查目录是否可写 */
$fp = @fopen($test_file, 'wb');
if ($fp === false)
{
echo "step 0305<br>";
return $; //如果目录中的文件创建失败,返回不可写。
}
if (@fwrite($fp, 'directory access testing.') !== false)
{
echo "step 0306<br>";
$ ^= 2; //目录可写可读011,目录可写不可读 010
}
@fclose($fp);
@unlink($test_file);
/* 检查目录是否可修改 */
$fp = @fopen($test_file, 'ab+');
if ($fp === false)
{
echo "step 0307<br>";
return $;
}
if (@fwrite($fp, "modify test.\r\n") !== false)
{
echo "step 0308<br>";
$ ^= 4;
}
@fclose($fp);
/* 检查目录下是否有执行rename()函数的权限 */
if (@rename($test_file, $test_file) !== false)
{
echo "step 0309<br>";
$ ^= 8;
}
@unlink($test_file);
}
/* 如果是文件 */
elseif (is_file($file_path))
{
echo "step 0310<br>";
/* 以读方式打开 */
$fp = @fopen($file_path, 'rb');
if ($fp)
{
echo "step 0311<br>";
$ ^= 1; //可读 001
}
@fclose($fp);
/* 试着修改文件 */
$fp = @fopen($file_path, 'ab+');
if ($fp && @fwrite($fp, '') !== false)
{
echo "step 0312<br>";
$ ^= 6; //可修改可写可读 111,不可修改可写可读011...
}
@fclose($fp);
/* 检查目录下是否有执行rename()函数的权限 */
if (@rename($test_file, $test_file) !== false)
{
echo "step 0313<br>";
$ ^= 8;
}
}
}
else
{
echo "step 0390<br>";
if (@is_readable($file_path))
{
echo "step 0391<br>";
$ ^= 1;
}
if (@is_writable($file_path))
{
echo "step 0392<br>";
$ ^= 14;
}
}
echo "step 04<br>";
return $;
}
?>我将4楼的程序添加几个标签,在成功的机器上运行的结果是:d:\inetpub\wwwroot
step 01
step 02
step 0301
step 0302
step 0304
step 0306
step 0308
step 0309
step 04
[15]
before exit