php 强制下载文件实现代码
程序员文章站
2022-06-20 23:47:09
复制代码 代码如下:
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('content-description: file transfer');
header('content-type: application/octet-stream');
header('content-disposition: attachment; filename='.basename($file));
header('content-transfer-encoding: binary');
header('expires: 0');
header('cache-control: must-revalidate, post-check=0, pre-check=0');
header('pragma: public');
header('content-length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
?
<?php
header("content-type: application/force-download");
header("content-disposition: attachment; filename=ins.jpg");
readfile("imgs/test_zoom.jpg");
?>
复制代码 代码如下:
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('content-description: file transfer');
header('content-type: application/octet-stream');
header('content-disposition: attachment; filename='.basename($file));
header('content-transfer-encoding: binary');
header('expires: 0');
header('cache-control: must-revalidate, post-check=0, pre-check=0');
header('pragma: public');
header('content-length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
?
<?php
header("content-type: application/force-download");
header("content-disposition: attachment; filename=ins.jpg");
readfile("imgs/test_zoom.jpg");
?>
上一篇: php实现邮件发送并带有附件
下一篇: 简单的php缓存类分享 php缓存机制