The following script fails if line #6 (.include …) is uncommented – no matter what the content of the file “somefile.php” is. Even for a 0-byte (empty) file. I was trying to move such functions and create a “utils.php” library, is that a big no-no in the PHP world? Error_log is empty. I am using PHP 5.2.17 on Linux 2.6.32. Thank you.
<?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>";
}
?>
There should be no
.before include. Dot is a concatenation operator in PHP and irrelevant here.Also please note that your
ini_set ('display_errors', 1);statement won’t help with parse errors for obvious reasons. Better set your settings inphp.inior web-server config.