You can do two things-

1. Read the file by providing a base directory path of the server where the
file exist.
Something like- //htdocs/httpfolder/files/audio/yourfile.mp3
You can take this in a variable " //htdocs/httpfolder/files/audio/".

2. Try using file_get_contents.
Something like $file = file_get_contents('
http://www.example.com/audio/file.mp3', false, $context);

Hope this helps.

Gaurav Kumar
Blog.OsWebStudio.com


On Wed, Dec 9, 2009 at 8:06 AM, c...@hosting4days.com <c...@hosting4days.com
> wrote:

> 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,
> c...@hosting4days.com
>
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to