, $ext $file , .
"" , .
, "//Finding MIME type":
$log = "file='".$file."'\n";
$log .= "ext='".$ext."'\n";
@file_put_contents("/tmp/page1.log", $log, FILE_APPEND);
, "/tmp/page1.log", , $file $ext .
"/tmp/page1.log" , , linux; , "file_put_contents" .
, "if" :
$content_types = array(
"pdf" => "application/pdf",
"doc" => "application/msword",
"txt" => "text/plain",
"rtf" => "application/rtf",
"docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation"
);
if (isset($content_types[$ext])) {
if (file_exists($file)) {
header("Content-disposition: attachment; filename= '$filename'");
header('Content-type: '.$content_types[$ext]);
readfile($file);
die("");
} else {
die("** '".$file."' does not exist **");
}
} else {
die("** Unhandled '".$ext."' extension **");
}
, , die(), , .
, , , ; , PHP Fileinfo.
.
, file_exists FALSE file_exists ; . clearstatcache() PHP.
user1419445