Force-Saving an Audio File

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi folks,

I'm trying to force save .mp3 files so this is a test page (found on the net). It works fine when:
$directory = "";  // so the audio is in the same local directory

but fails when I use a REAL web directory - (the audio file is here - http://mysite.com/test1/audio.mp3 )
$directory = "http://mysite.com/test1/";;

says - The file $file was not found.

Q: Any ideas how to get it to download from the website?

=====



<?php

$file = 'audio1.mp3';

$directory = "http://mysite.com/test1/";;
//$directory = "";
$path = "$directory$file";

if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');

$file_extension = strtolower(substr(strrchr($path,"."),1));

if( $file == "" )
{
echo "<html>
<head>
<title>File not found.</title>
</head>
<body>
File not found.
</body>
</html>";
exit;
} elseif (! file_exists( $path ) )
{
echo "<html>
<head>
<title>The file $file was not found.</title>
</head>
<body>
The file $file was not found.<br />
- path - $path
</body>
</html>";exit;
};
switch( $file_extension )
{
case "pdf": $ctype="application/pdf"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
case "wav":
case "mp3": $ctype="application/iTunes"; break;
default: $ctype="application/force-download";
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"".basename ($path)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($path));

readfile("$path");
exit();

?>



Thanks,
cool@xxxxxxxxxxxxxxxx






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux