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

 2025-01-16  阅读 513  评论 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强制图片下载的方法

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
     发布于 1月前回复该评论
  • 写的很不错,学到了!
显示更多评论

发表评论:

管理员

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

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

页面耗时0.0289秒, 内存占用1.94 MB, 访问数据库31次

冀ICP备19034377号