I used the mkdir() function to create a directory and used the 0777 to give it permissions. I also want to create a file inside that directory and write to it. I know how to execute this code, but what I don't know how to do is make sure this file dynamically has permissions so it could be written too. when I go to write my text it says I don't have permissions and it doesn't even create the file. If I am not mistaken, the 'w' in the fopen statement will create a new file if it is not already created.
Here is example of the code I am using:
$new_dir = "mypath/to/directory";
if(file_exists($new_dir))
{
echo "error! .......";
exit;
}
mkdir($new_dir, 0777);
$filename = "myFile.txt";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w')) {
print "Cannot open file ($filename)";
exit;
}
if (!fwrite($handle, $write)) {
print "Cannot write to file ($filename)";
exit;
}
fclose($handle);
} else {
print "The file $filename is not writable";
}
Any ideas on how I can accomplish this?
Thanks again for your time.