本文實例講述了php簡單實現文件或圖片強制下載的方法。分享給大家供大家參考,具體如下:
//下載
function downregcaseAction() {
$file="upload/regcase.jpg";
if(isfile($file)) {
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename(file));
readfile(file);
exit;
} else {
echo "文件不存在!";
exit;
}
}
更多關於PHP相關內容感興趣的讀者可查看本站專題:《php文件操作總結》、《PHP圖形與圖片操作技巧匯總》、《PHP數組(Array)操作技巧大全》、《PHP基本語法入門教程》、《PHP運算與運算符用法總結》、《php面向對象程序設計入門教程》、《PHP網絡編程技巧總結》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。