我有一个需要将一些 html 写入文件的 cron 脚本。
需要编写 HTML 的文件位于 public_html 目录中,而脚本位于该目录上方的不同位置。如果我手动 CHMOD 一切正常,但我不想将其保留为 0777 或继续手动操作,所以我想让我的脚本为我做这件事。
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;
}
不幸的是,它似乎不起作用。为什么?