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学习的路线图

浅析php学习的路线图

1.php初级教程 初级教程主要的页面设置的,就是 html+js+div+css2.中级教程 中级的话开始接触php,就是php核心编程和数据库的交互3.高级课程 这个主要...

php 把数字转换成汉字的代码

直接上实例,写到 千亿上了。 /** * @author ja颂 * 把数字1-1亿换成汉字表述,如:123->一百二十三 * @param [num] $num [数字]...

php获取数组元素中头一个数组元素值的实现方法

本文实例讲述了php获取数组元素中头一个数组元素值的实现方法。分享给大家供大家参考。具体如下: 在php的内置函数中,获取数组元素值的函数主要有 reset next current p...

Php注入点构造代码

把下面保存成 Test.asp 复制代码 代码如下:<?   $mysql_server_name = "localhost";&...

php ci框架中加载css和js文件失败的解决方法

在将html页面整合到ci框架里面的时候,加载css和js失败,弄了半天发现ci框架是入口的框架,对框架中文件的所有请求都需要经过index.php处理完成,当加载外部的css和js文件...