如何立即使用php头文件启动文件下载 [英] How to start file download instantly using php headers

查看:99
本文介绍了如何立即使用php头文件启动文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我只是想知道如何可以立即开始播放mp3下载,因为反对在您直接访问浏览器时才开始播放。



最好使用php头。



所以基本上当你点击文件,我想要一个下载框出现保存保存等。现在它只是打开并开始播放在浏览器中。



感谢

解决方案

创建一个重定向到MP3文件的PHP文件,并将您的链接指向该PHP文件。



代码如下:

 <?php 
header('Content-type:audio / mpeg');
header('Content-Disposition:attachment; filename =fileName.mp3');
readfile('originalFile.mp3');
?>

注意:设置Content-Disposition标题的行是关键的。


well I'm just wondering how I can get an mp3 download to start instantly, as oppose to it simply starting to play in the browser when you directly go to it.

Preferably using php headers.

So essentially when you click the file, I want a download box to appear saving save etc. Right now it just opens and starts playing in the browser.

Thanks

解决方案

You'll need to create a PHP file that "redirects" to the MP3 file, and point your links to that PHP file.

Code as below:

<?php
header('Content-type: audio/mpeg');
header('Content-Disposition: attachment; filename="fileName.mp3"');
readfile('originalFile.mp3');
?>

Note: The line that sets the Content-Disposition header is the critical one.

这篇关于如何立即使用php头文件启动文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆