I am running PHP 5.5.9 on Ubuntu 14.04. I'm having trouble writing to a file. I feel like this has to be a file permissions problem because I'm pretty sure the code is correct. The user that I'm logged in as has permissions to write in the folders that I am trying to write into, but I'm not sure if the localhost does. I'm not sure what the name of the localhost user is in order to use chmod
. I tried using chmod 777 -R /var/www/html
and the script is still is not able to write to my target folder, which has the path /var/www/html/Projects/MD_ScrapingTool/files
. Here is my code:
$file = 'filetest.txt';
if($handle = fopen($file, 'w')) {
$content = "123\n456";
fwrite($handle, $content);
fclose($handle);
} else {
echo "Could not open file for writing.";
}