这篇文章主要介绍了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免费学习笔记(深入)”;











