Rename and download mp3 file

女生的网名这么多〃 提交于 2019-12-23 02:52:10

问题


for example i have link :

http://example.com/song.mp3

and when user download it, file will be renamed to

artist-song.mp3

I used this code :

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://example.com/song.mp3");
header('Content-Disposition: attachment; filename="a-s.mp3"');
exit();
?>

But it doesn't work. What do I need to do?


回答1:


http://ie2.php.net/readfile

the example in the docs is pretty much what you want.

in particular, see the header('Content-Disposition: attachment; filename='.basename($file)); bit




回答2:


The Location header causes the client browser to request the file from the specified URL. That'll be a completely NEW and SEPARATE http request, with its own content-type/content-disposition headers.

The Content-disposition header you're issuing here will not be honored, as it is from a completely DIFFERENT request.



来源:https://stackoverflow.com/questions/8144270/rename-and-download-mp3-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!