Jump to content

audio download & header


aniesh82

Recommended Posts

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

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.