PHP强制性文件下载

强制性文件下载
如果你需要下载特定的文件而不用另开新窗口,下面的代码片段可以帮助你。
[code lang=”php”]
function force_download($file)
{
$dir = "../log/exports/";
if ((isset($file))&&(file_exists($dir.$file))) {
header("Content-type: application/force-download");
header(‘Content-Disposition: inline; filename="’ . $dir.$file . ‘"’);
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($dir.$file));
header(‘Content-Type: application/octet-stream’);
header(‘Content-Disposition: attachment; filename="’ . $file . ‘"’);
readfile("$dir$file");
} else {
echo "No file selected";
}
}
[/code]
语法:
[code lang=”php”]
<php
force_download("image.jpg");
?>

[/code]


已发布

分类

来自

标签:

0 0 投票数
文章评分
订阅评论
提醒
guest
0 评论
最旧
最新 最多投票
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x