php 强制下载文件实现代码

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?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在不同页面间传递Json数据示例代码

gettest.php文件: 复制代码 代码如下: <?php $value["name"]= urlencode("我的姓名"); $value["pass"]= urlenco...

php实现获取及设置用户访问页面语言类

本文实例讲述了php实现获取及设置用户访问页面语言类,分享给大家供大家参考。具体分析如下: 该实例User Language Class 获取/设置用户访问的页面语言,如果用户没有设置访...

Yii2中datetime类的使用

前言 以前更改时间格式的时候经常使用date方法,后来知道php竟然自带datetime类处理时间格式,记录一下用法,方便以后使用 实例化 在yii 1.1中,可以直接写成 $d...

php中session退出登陆问题

在php中,如果使用的session来判断用户是否登陆,退出时,则可以如此: session_start();session_destroy(); 会话即表示已经结束。下一句话应该写js...

php递归删除指定文件夹的方法小结

本文实例总结了两种php递归删除指定文件夹的方法。分享给大家供大家参考。具体如下: 方法一: function recursiveDelete($dir) { if ($ha...