也许我不理解 php 的 chmod() 函数应该如何工作,但我遇到它返回 TRUE(表示成功)但实际上并未修改权限。
我正在处理一个已上传到我的 Web 服务器的 tmp 目录的文件。
$fn = $value["tmp_name"];
$fps = fileperms($fn);
$testMsg .= "file permissions are $fps\n";
$testMsg .= "(which is " . substr(sprintf('%o', $fps), -4) . ")\n";
$arr = posix_getpwuid(fileowner($fn));
$testMsg .= "file owner is " . $arr["name"] . "\n";
$testMsg .= "running as: " . trim(shell_exec('whoami')) . "\n";
//can i chmod it?
$didChmod = chmod($fn, 0644);
$testMsg .= "chmod: $didChmod\n";
$fps = fileperms($fn);
$testMsg .= "NEW file permissions are $fps\n";
$testMsg .= "(which is " . substr(sprintf('%o', $fps), -4) . ")\n";
上面的输出是:
file permissions are 33152
(which is 0600)
file owner is www-data
running as: www-data
chmod: 1
NEW file permissions are 33152
(which is 0600)
如您所见, chmod() 报告成功但没有更改权限。
谢谢