Nginx實現MP3的播放和下載


參考:

http://segmentfault.com/blog/p_chou/1190000000437323?utm_source=tuicool

http://www.netingcn.com/nginx-add-header.html

http://nginx.org/cn/docs/http/ngx_http_rewrite_module.html

 

項目需要MP3下載的功能,GOOGLE了幾篇文章,參考實現了這個功能,用時大概3個番茄鍾,了解了Nginx內置變量和正則判斷請求URL的方法。

需求:

打開URL:http://localhost/a_short_song.mp3 ,在線播放音樂

打開URL:http://localhost/a_short_song.mp3?download=a.mp3 實現MP3下載,並重命名文件名為指定參數: a.mp3

Nginx配置文件中的配置代碼如下:

        location / {            
			index index.html index.php; 
			if ($arg_download){ 
				add_header Content-Disposition "attachment; filename=$arg_download";				 
			} 
        }

 

問題:中文文件名時有問題,如http://localhost/a_short_song.mp3?download=張三.mp3時,下載的文件名稱為:%E5%BC%A0%E4%B8%89.mp3,有待解決一下。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM