After ages of programming in php this question seems really weird still to me.
I want to make a file writable dinamically to not have problem with permissions in production / development …. but it still gives me trouble.
Can someone gives me explanation on what am I wrong?
// 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);
Change
chmod($fileRequest, '0777')tochmod($fileRequest, 0777). The string'0777'will be converted to a numeric value, which will be 777 decimal, which is not what you expect; what you really want is 0777 octal.