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");
?>

相关文章

simplehtmldom Doc api帮助文档

API Reference Helper functions object str_get_html ( string $content ) Creates a DOM object f...

php中最简单的字符串匹配算法

本文实例讲述了php中最简单的字符串匹配算法。分享给大家供大家参考。具体实现方法如下: 复制代码 代码如下:<?php /* 最简单字符串匹配算法php实现方式 &n...

PHP设计模式之装饰器模式实例详解

PHP设计模式之装饰器模式实例详解

本文实例讲述了PHP设计模式之装饰器模式。分享给大家供大家参考,具体如下: 装饰器模式又叫装饰者模式。装饰模式是在不必改变原类文件和使用继承的情况下,动态地扩展一个对象的功能。它是通过创...

谈谈PHP连接Access数据库的注意事项

谈谈PHP连接Access数据库的注意事项

首先需要注意: 安装access 数据库的时候 需要安装与本机系统相互匹配的office版本,win7 64位的系统 ,那么Office也要是64位的 最好装 office2010。。。...

php中简单的对称加密算法实现

前言 在网上找到了一个不错的PHP方面的对称加密算法;在PHP的语法环境里,有urlencode与urldecode,base64_encode和base64_decode自带的对称算法...