I have a cron script that needs to write some html into a file.
The file that needs to have HTML written is in public_html dir and the script in a different location, just above that dir. If I CHMOD manually everything works, but I don not want to leave it as 0777 or keep on doing it manually, so I wanted to make my script to do it for me.
ob_start();
// build my HTML
$myHTML = ob_get_clean();
// CODE TO SAVE INTO INCLUDE <<<
$filename = 'home/public_html/file.php';
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w')) {
mail("support@domain.com", "Failed to create include", "Script failed to create include", "From: Support <support@domain.com>");
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, ($myHTML)) === FALSE) {
mail("support@domain.com", "Failed to create include", "Script failed to create include", "From: Support <support@domain.com>");
exit;
}
fclose($handle);
} else {
mail("support@domain.com", "Failed to create include", "Script failed to create include", "From: Support <support@domain.com>");
exit;
}
Unfortunately it does not seem to work. Why?
This looks like an absolute path
home/public_html/are you sure you didn’t mispell it ?You can
If
trueis returned then you can tryWith
You can check how much bytes you’ve written in it.
If
falseis returned this means you’re having a permission issue