A question about file permissions when saving a file that when non existent, is created initially as new file.
Now, this all goes well, and the saved file appear to have mode 644
.
What to I have to change here, in order to make the files save as mode 777
?
Thanks a thousand for any hints, clues or answers. The code that I think is relevant here I have included:
/* write to file */
self::writeFileContent($path, $value);
/* Write content to file
* @param string $file Save content to which file
* @param string $content String that needs to be written to the file
* @return bool
*/
private function writeFileContent($file, $content){
$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
return true;
}
Easiest way to set permissions to 777 is to connect to Your server through FTP Application like FileZilla, right click on folder, module_installation, and click Change Permissions - then write 777 or check all permissions. Save this answer.
The chmod() function changes permissions of the specified file.
777 - all can read/write/execute (full access). 755 - owner can read/write/execute, group/others can read/execute. 644 - owner can read/write, group/others can read only.
PHP has a built in function called bool chmod(string $filename, int $mode )
http://php.net/function.chmod
private function writeFileContent($file, $content){
$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
chmod($file, 0777); //changed to add the zero
return true;
}
You just need to manually set the desired permissions with chmod()
:
private function writeFileContent($file, $content){
$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
// Set perms with chmod()
chmod($file, 0777);
return true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With