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实现图片上传并进行替换操作

首先建立两个文件: change.html 和 change.php change.html 文件的表单代码如下: <html> <head> <tit...

PHP的Laravel框架中使用AdminLTE模板来编写网站后台界面

PHP的Laravel框架中使用AdminLTE模板来编写网站后台界面

AdminLTE 是一个基于Bootstrap 3.x的免费高级管理控制面板主题,完全响应式管理,适合从小型移动设备到大型台式机很多的屏幕分辨率。 AdminLTE的特点: 充分...

php根据用户语言跳转相应网页

当来访者浏览器语言是中文就进入中文版面,国外的用户默认浏览器不是中文的就跳转英文页面。 <?php $lan = substr( $HTTP_ACCEP...

php构造函数与析构函数

php构造函数是对象创建完成后,第一个自动调用的方法,析构函数是当对象被释放之前最后一个自动调用的方法。本文章向大家介绍php构造函数与析构函数。 php构造函数 1.是对象创建完成后,...

有关PHP性能优化的介绍

PHP优化对于PHP的优化主要是对php.ini中的相关主要参数进行合理调整和设置,以下我们就来看看php.ini中的一些对性能影响较大的参数应该如何设置。 # vi /etc/php....