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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.