php通过修改header强制图片下载的方法

 2025-01-16  阅读 683  评论 8  点赞 468

摘要:本文实例讲述了php通过修改header强制图片下载的方法。分享给大家供大家参考。具体实现方法如下: function downloadfile($file){ $file_name = $file; $mime = 'application/force-download'; header('pragma: public'); // required header('expires: 0'); // no cache hea

本文实例讲述了php通过修改header强制图片下载的方法。分享给大家供大家参考。具体实现方法如下:

php通过修改header强制图片下载的方法-第1张-php-LS'Blog-保定PHP程序员老宋个人博客

function downloadfile($file){
 $file_name = $file;
 $mime = 'application/force-download';
 header('pragma: public'); // required
 header('expires: 0'); // no cache
 header('cache-control: must-revalidate, post-check=0, pre-check=0');
 header('cache-control: private',false);
 header('content-type: '.$mime);
 header('content-disposition: attachment; filename="'.basename($file_name).'"');
 header('content-transfer-encoding: binary');
 header('connection: close');
 readfile($file_name); // push it out
 exit();
}

希望本文所述对大家的php程序设计有所帮助。


标签:phpphp教程

评论列表:

  •   xiedaimade
     发布于 2025-01-14 19:48:16回复该评论
  • 写的很不错,学到了!
  •   weihang
     发布于 2025-01-15 01:48:16回复该评论
  • 哈哈哈不错!
  •   xixi2
     发布于 2025-01-15 07:48:16回复该评论
  • 非常棒谢谢了!
  •   danney
     发布于 2025-01-15 19:48:16回复该评论
  • 不错,学习了!
  •   hahaha1
     发布于 2025-01-16 01:48:16回复该评论
  • 非常棒谢谢了!
  •   henbucuo
     发布于 2025-01-16 13:48:16回复该评论
  • 非常棒谢谢了!
显示更多评论

发表评论:

管理员

承接各种程序开发,外贸网站代运营,外贸网站建设等项目
  • 内容2471
  • 积分67616
  • 金币91666

Copyright © 2024 LS'Blog-保定PHP程序员老宋个人博客 Inc. 保留所有权利。 Powered by LS'blog 3.0.3

页面耗时0.0365秒, 内存占用2.04 MB, 访问数据库32次

冀ICP备19034377号