This is unsafe and you will not need to do this.
In addition to the security implications of @ceejayoz, if allow_url_fopen PHP is enabled, you can also insert any URL into $url . Thus, your server can be easily used for streaming large amounts of data from other servers with all possible consequences.
This file maintenance method should only be used when it is truly needed. It consumes more resources (because you need to start an expensive PHP process) than request a static resource through a web server.
In any case, this is not necessary. It seems your web server is not serving the correct content-type header along with your MP3 files. This is what you have to fix.
Itβs possible if youβre in Apache by adding the .htaccess file to the directory where the MP3 files are located, with the following contents:
AddType audio/mpeg .mp3
already fixes the problem. If this is not the case, but force-download works, try
AddType application/force-download .mp3
source share