PHP 写出临时静态html文件到根目录
以下是一个示例代码,可以将临时静态HTML文件写入到根目录中:
<?php
// 设置文件名和内容
$file_name = "temp.html";
$file_content = "<html><head><title>Temporary HTML</title></head><body><h1>This is a temporary HTML file.</h1></body></html>";
// 写入文件到根目录
$root_path = $_SERVER['DOCUMENT_ROOT'];
$file_path = $root_path . "/" . $file_name;
$file = fopen($file_path, "w");
fwrite($file, $file_content);
fclose($file);
// 输出成功信息
echo "Temporary HTML file written to root directory.";
?>
请注意,这个代码可能需要更改文件权限或使用其他安全措施,以确保文件写入的安全性和可靠性。
原文地址: https://www.cveoy.top/t/topic/EW3 著作权归作者所有。请勿转载和采集!