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

相关文章

相对路径转化成绝对路径

提取 Gregarius中的一个函数。可以把网页中的相对路径自动转化成绝对路径。 <?  function relative_to_absolute(...

PHP基于timestamp和nonce实现的防止重放攻击方案分析

本文实例讲述了PHP基于timestamp和nonce实现的防止重放攻击方案。分享给大家供大家参考,具体如下: 以前总是通过timestamp来防止重放攻击,但是这样并不能保证每次请求都...

php使用pdo连接并查询sql数据库的方法

本文实例讲述了php使用pdo连接并查询sql数据库的方法。分享给大家供大家参考。 具体实现代码如下: 复制代码 代码如下:$login = "root"; $passwd = "my...

php操作xml入门之cdata区段

本文实例讲述了php操作xml入门之cdata区段。分享给大家供大家参考。具体分析如下: 复制代码 代码如下:<?xml version="1.0" encoding="u...

php实现的RSS生成类实例

本文实例讲述了php实现的RSS生成类。分享给大家供大家参考。具体如下: class RSS { var $title; var $link; var $description...