php 强制下载文件(诸如mp3)实现方法
内容摘要
这篇文章主要为大家详细介绍了php 强制下载文件(诸如mp3)实现方法,具有一定的参考价值,可以用来参考一下。
一些诸如 mp3 类型的文件,通常会在客户端浏览器中直接被播放或使用。
一些诸如 mp3 类型的文件,通常会在客户端浏览器中直接被播放或使用。
文章正文
这篇文章主要为大家详细介绍了php 强制下载文件(诸如mp3)实现方法,具有一定的参考价值,可以用来参考一下。
一些诸如 mp3 类型的文件,通常会在客户端浏览器中直接被播放或使用。php强制下载文件(诸如mp3),如果你希望它们强制被下载,也没问题,对此感兴趣的朋友,看看idc笔记做的技术笔记。经测试代码如下:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <code class = "php" > /** * 强制下载文件 * * @param * @author php教程 www.idcnote.com **/ 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教程(www.idcnote.com) ***/ </code> |
注:关于php 强制下载文件(诸如mp3)实现方法的内容就先介绍到这里,更多相关文章的可以留意
代码注释