aniesh82 Posted February 4, 2008 Share Posted February 4, 2008 Hi I have tried to add a 'download' option to the web page, so users can easily download the audio files (mp3 & wav format). The code that i used in the download page is below: <?php $file = addslashes($_GET['audiopath']); if($file) { $extension = pathinfo($file,PATHINFO_EXTENSION); if(strtolower($extension) == 'mp3') { $ctype = "audio/x-mp3"; } elseif(strtolower($extension) == 'wav' OR strtolower($extension) == 'wave' ) { $ctype = "audio/x-wav"; } header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Type: $ctype"); header("Content-Length: ".filesize($file)); header("Content-Disposition: attachment; filename=\"".basename($file)."\";" ); readfile("$file"); exit(); } ?> When I tried to play the audio file, I got the following from the Media Player: "Windows Media Player cannot play the file. The Player might not support the file type or might not support the codec that was used to compress the file.". How can I solve this ? Regards, PHP Developer Link to comment https://forums.phpfreaks.com/topic/89416-audio-download-header/ Share on other sites More sharing options...
Stooney Posted February 4, 2008 Share Posted February 4, 2008 You need the right codecs to play the file it looks like. Link to comment https://forums.phpfreaks.com/topic/89416-audio-download-header/#findComment-457880 Share on other sites More sharing options...
aniesh82 Posted February 4, 2008 Author Share Posted February 4, 2008 Hi Thank you for your reply. I have tried to play the audio directly from the URL and it is playing in the Media Player perfectly. But the it doesn't play when I download the audio file using the code above Link to comment https://forums.phpfreaks.com/topic/89416-audio-download-header/#findComment-457899 Share on other sites More sharing options...
Stooney Posted February 4, 2008 Share Posted February 4, 2008 Are you trying 'open' the file or 'save' it? Link to comment https://forums.phpfreaks.com/topic/89416-audio-download-header/#findComment-457915 Share on other sites More sharing options...
aniesh82 Posted February 4, 2008 Author Share Posted February 4, 2008 I have tried to open the file from the download pop up and save..But both cases, it returns the same error that I mentioned in my first post. But what it is working fine in Mozilla. Another thing I noted in the audio file that I downloaded using the explorer is the size. It shows o bytes, means it doesn't transfer anything!!! I have changed that code with another got from phpfreaks forum.. Now it is like below, but the results are same. <?php $file = addslashes($_GET['audiopath']); if($file) { $extension = pathinfo($file,PATHINFO_EXTENSION); if(strtolower($extension) == 'mp3') { $ctype = "audio/x-mp3"; } elseif(strtolower($extension) == 'wav' OR strtolower($extension) == 'wave' ) { $ctype = "audio/x-wav"; } header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Type: $ctype"); header("Content-Disposition: attachment; filename=\"".basename($file)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($file)); @readfile($file); exit(); } ?> Link to comment https://forums.phpfreaks.com/topic/89416-audio-download-header/#findComment-457930 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.