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中的UNICODE 编码与解码

方法一:复制代码 代码如下:<?phpfunction unicode_encode($name){    $name = iconv('UTF-8'...

php设计模式 Bridge (桥接模式)

复制代码 代码如下: <?php /** * 桥接模式 * * 将抽象部份与它实现部分分离,使用它们都可以有独立的变化 */ abstract class Implementor...

简单的PHP多图上传小程序代码

先上源代码,你可以copy到自己的电脑上去运行~ 复制代码 代码如下: <html> <meta http-equiv="Content-Type" content="...

php打开本地exe程序,js打开本地exe应用程序,并传递相关参数方法

实例如下: <? //include_once("inc/auth.inc.php"); include_once("inc/conn.php"); $HTML_PAG...

PHP函数shuffle()取数组若干个随机元素的方法分析

本文实例讲述了PHP函数shuffle()取数组若干个随机元素的方法。分享给大家供大家参考,具体如下: 有时候我们需要取数组中若干个随机元素(比如做随机推荐功能),那么PHP要如何实现呢...