php 强制下载文件诸如mp3实现方法

一些诸如 mp3 类型的文件,通常会在客户端浏览器中直接被播放或使用。PHP强制下载文件(诸如mp3),如果你希望它们强制被下载,也没问题,感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
经测试代码如下:

/**
 * 强制下载文件
 *
 * @param 
 * @author 编程之家 jb51.cc jb51.cc
 **/
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(); 
}


/***   来自编程之家 jb51.cc(jb51.cc)   ***/

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...