如果第 6 行 (.include ...) 未注释,则以下脚本将失败 - 无论文件“somefile.php”的内容是什么。即使是 0 字节(空)文件。我试图移动这些函数并创建一个“utils.php”库,这是 PHP 世界中的一个大禁忌吗?Error_log 为空。我在 Linux 2.6.32 上使用 PHP 5.2.17。谢谢你。
<?php // File: index.php
error_reporting (E_ALL);
ini_set ('display_errors', 1);
//Uncomment the following line and the script fails
//.include "somefile.php";
function imageToBrowser ($pseudonym, $filePath) {
header("Pragma: public");
header("Expires: 0");
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0', false);
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header("Content-Length: ".(string)(filesize($filePath)));
header('Content-Type: application/x-download');
header('Content-Disposition: attachment; filename="'.$pseudonym.'.png"');
header('Content-Transfer-Encoding: binary');
if ($file = fopen($filePath, 'rb')) {
while(!feof($file) and (connection_status()==0)) {
print(fread($file, filesize($filePath)));
flush();
}
fclose($file);
}}
if (isset($_GET['showImage']) && ($imageMask = $_GET['showImage'])) {
imageToBrowser ($imageMask, 'Clear64.png'); // Use any .png file in $cwd
} else {
echo "<html><body><center>\n";
echo "<img border='0' src=\"{$_SERVER['PHP_SELF']}?showImage=365\" alt=\"Missing Image\"/>\n";
echo "</center></body></html>";
}
?>