【发布时间】:2012-06-12 10:29:14
【问题描述】:
经过多年的 php 编程,这个问题对我来说仍然很奇怪。
我想让一个文件在动态上可写,以免生产/开发中的权限出现问题....但它仍然给我带来了麻烦。
谁能解释一下我哪里错了?
// permissions -- the folder writable by www-data
//drwxrwxrwx 2 www-data www-data 4096 mag 24 12:19 Details
// then the file not writable by the owner
-r----x--t 1 www-data www-data 0 giu 8 12:48 /home/giuseppe/homeProj//Ariprova/trunk/PhpCsv/phpcsv/ConfigClasses/Helpers/Virtuemart2/Details/324-PartsToAdd.json
// then the code
if (!file_exists($fileRequest)) { // it's found
throw new Exception ('File non trovato. Nome File completo: '.$fileRequest. ' con cartella '. getcwd());
}
if (!is_writable($fileRequest)) {
$results = @chmod($fileRequest, '0777'); //this gives true
}
$fileReq = fopen($fileRequest, 'w');
fwrite($fileReq, 'a string' ); // this writes nothing on file
fclose($fileReq);
【问题讨论】:
-
您是否尝试过使用
chmod而不是@chmod(抑制错误消息)? -
也可以试试 chmod($fileRequest, 777);
-
@Rishabh 777 十进制不是 0777 八进制。
标签: php linux permissions filesystems