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中Redis的应用--消息传递

php中Redis的应用--消息传递

阅读目录 1、摘要 2、实现方法 3、一对一消息传递 4、多对多消息传递 1、摘要 消息传递这一应用广泛存在于各个网站中,这个功能也是一个网站必不可少的。常见的消息传递应用有,新浪微博中...

PHP实现获取文件后缀名的几种常用方法

本文实例讲述了PHP实现获取文件后缀名的几种常用方法。分享给大家供大家参考。具体如下: 方法1: function get_file_type($filename){ $type...

PHP合并两个或多个数组的方法

PHP合并两个或多个数组的方法

使用运算符“+” PHP的数组运算符“+”可以用来联合两个(或多个数组)。 <?php header("content-type:text/html;charset=...

php获取json数据所有的节点路径

之前我们讲解过使用javascript获取json数据节点路径的问题,今天我们更进一步,讲解下php获取json数据所有的节点路径 <?php function it...

PHP 删除文件与文件夹操作 unlink()与rmdir()这两个函数的使用

先看一下代码 复制代码 代码如下: <? function deldir($dir) { //先删除目录下的文件: $dh=opendir($dir); while ($file=...