php 强制下载文件实现代码
程序员文章站
2023-11-16 12:29:34
复制代码 代码如下:
<?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判断手机访问还是电脑访问示例分享
下一篇: sql函数:开窗函数简介