在php編程的年齡後,這個問題似乎對我來說真的很奇怪。php設置權限文件,使其可寫
我想製作一個文件dinamically寫入沒有生產/開發權限的問題....但它仍然給我麻煩。
有人可以給我解釋我錯了什麼?
// 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'(這會抑制錯誤消息)? – Michael
也嘗試chmod($ fileRequest,777); – Rishabh
@Rishabh 777十進制不是0777八進制。 – lanzz