Reputation: 4898
I have this code triggered when user download mp3 file
$file = $_GET['file'];
$ext = pathinfo($file, PATHINFO_EXTENSION);
$match_array =array('pdf','mp3','mpa','ra','wav','wma','mid','m4a','m3u','iff','aif');
if(in_array($ext,$match_array)){
header("Content-type: application/".$ext);
header("Content-Disposition: attachment; filename=". $file);
readfile($file);
}
but downloaded file is 0 byte so what is the problem ?
File exists and $file
contain this value
https://mysite/upload/1/myfile.mp3
Upvotes: 0
Views: 1427
Reputation: 4898
It was server problem and PHP was set on old 5 version so when I changed the version to 7 it worked fine.
Upvotes: 1
Reputation: 1753
Your issue might be a configuration problem.
Remember
allow_url_fopen
has to be = on in php.ini From Here
Another alternative might be to use the below code instead and save it to your local filesystem.
$localPath = "tmp/foo.mp3";
$contents = file_get_contents($file);
$save = file_put_contents($localPath, $contents);
Upvotes: 2