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实现获取客户端IP并获取IP信息

代码很简洁,功能很实用,这里就不多废话了,直接奉上: 复制代码 代码如下: <?php /**  * 获取客户端IP  * @param  i...

php判断当前用户已在别处登录的方法

本文实例讲述了php判断当前用户已在别处登录的方法。分享给大家供大家参考。具体分析如下: 主要思路如下: 1.登录时,将用户的SessionID记录下来 2.验证登录时,将记录的该用户S...

thinkphp中的多表关联查询的实例详解

thinkphp中的多表关联查询的实例详解  在进行后端管理系统的编程的时候一般会使用框架来进行页面的快速搭建,我最近使用比较多的就是thinkphp框架,thinkphp框架...

php 获得汉字拼音首字母的函数

php获取汉字拼音的第一个字母复制代码 代码如下:<?php function getinitial($str) { $asc=ord(substr($str,0,1)); if...

浅谈php正则表达式中的非贪婪模式匹配的使用

通常我们会这么写: 复制代码 代码如下: $str = "http://www.baidu/.com?url=www.sina.com/"; preg_match("/http:(.*)...