giu*_*ppe 0 php linux filesystems permissions
经过几年的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);
Run Code Online (Sandbox Code Playgroud)
更改chmod($fileRequest, '0777')
到chmod($fileRequest, 0777)
.该字符串'0777'
将被转换为数字值,这将是777十进制数,这不是您所期望的; 你真正想要的是0777八进制.