if($_POST['mode']=="save") {
$root = $_SERVER['DOCUMENT_ROOT'];
$path = "/mcboeking/";
$path = $root.$path;
$file_path = $_POST['path'];
$file = $path.$file_path;
if(!file_exists($file)) {
die('file not found');
} else {
header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-Type: application/force-download');
header("Content-Disposition: attachment; filename=\"".basename($file)."\";");
header("Content-Length: ".filesize($file));
readfile($file);}}
只要我下載的文件,並打開它,我得到一個錯誤信息。當我嘗試打開.doc文件時,我收到消息:文件結構無效。 而當我嘗試打開一個.jpg文件時:此文件無法打開。它可能已損壞或者Preview無法識別的文件格式。強制下載文件Broken Headers錯誤?
但是當我下載PDF文件時,它們沒有任何問題打開。
有人可以幫助我嗎?
P.s.我嘗試了不同的標題,包括: header('Content-Type:application/octet-stream');