下面下載時是代碼片段使用ReadFile函數強制下載:爲什麼我們調用exit函數在PHP中使用ReadFile函數
<?php
if($type == 1){
$path = "assets/images/katiba.pdf";
}else if($type == 2){
$path = "assets/images/katiba2.pdf";
}else if($type == 3){
$path = "assets/images/katiba3.pdf";
}
if (file_exists($path)) {
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($path));
readfile($path);
exit;
}
?>
請爲什麼我們調用exit函數在最後。請幫助!
刪除'exit'和'回聲 「東西」;'頭之後,檢查發生了什麼? – C2486