[PHP] downloading winword & mp3 files the fancy way through a browser

2009-08-26 Thread Grega Leskovšek
I tried to download the file from another server the fancy way in PHP, but
it just display blank screen. Can You please look at my code:

http://aa.yolasite.com/resources/happytears.doc";;
// $filepath = "http://users.skavt.net/~gleskovs/else/happytears.doc";;
  if (file_exists($filepath)) {
 header("Content-Type: application/force-download");
 header("Content-Disposition:filename=\"happytears.doc\"");
 $fd = fopen($filepath,'rb');//I tried also just 'r' and am not clear on
which documents should I add b for binary? As I understand only text plain
files and html files and php etc files are without 'b'. All documents,
presentations, mp3 files, video files should have also 'b' for binary along
r. Am I wrong?
 fpassthru($fd);
 fclose($fd);
  }
?>
Both filepaths are valid and accessible to the same document. I double
checked them. Please help me. Thanks in advance, Yours, Grega


Re: [PHP] downloading winword & mp3 files the fancy way through a browser

2009-08-26 Thread Ryan Cavicchioni
On Wed, Aug 26, 2009 at 03:38:27PM +0200, Grega Leskov??ek wrote:
> I tried to download the file from another server the fancy way in PHP, but
> it just display blank screen. Can You please look at my code:
> 
> $filepath = "http://aa.yolasite.com/resources/happytears.doc";;

Try using a local filepath instead of a URL.

Example: $filepath = "/path/to/file/";

Regards,
Ryan

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



Re: [PHP] downloading winword & mp3 files the fancy way through a browser

2009-08-26 Thread Jim Lucas
Grega Leskovšek wrote:
> I tried to download the file from another server the fancy way in PHP, but
> it just display blank screen. Can You please look at my code:
> 
>  $filepath = "http://aa.yolasite.com/resources/happytears.doc";;
> // $filepath = "http://users.skavt.net/~gleskovs/else/happytears.doc";;
>   if (file_exists($filepath)) {

I see in the manual that file_exists can now check URLs, but my guess
would be that it needs to have the allow_url_fopen statement in the
php.ini set to "On".

See

>  header("Content-Type: application/force-download");
>  header("Content-Disposition:filename=\"happytears.doc\"");
>  $fd = fopen($filepath,'rb');//I tried also just 'r' and am not clear on
> which documents should I add b for binary? As I understand only text plain
> files and html files and php etc files are without 'b'. All documents,
> presentations, mp3 files, video files should have also 'b' for binary along
> r. Am I wrong?
>  fpassthru($fd);
>  fclose($fd);
>   }
> ?>
> Both filepaths are valid and accessible to the same document. I double
> checked them. Please help me. Thanks in advance, Yours, Grega
>

See what you get with this
http://aa.yolasite.com/resources/happytears.doc";;
if (file_exists($filepath)) {
  echo 'File found';
} else {
  echo 'File NOT found';
}
?>

Jim


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



Re: [PHP] downloading winword & mp3 files the fancy way through a browser

2009-08-26 Thread Ryan Cavicchioni
On Wed, Aug 26, 2009 at 03:38:27PM +0200, Grega Leskov??ek wrote:
> I tried to download the file from another server the fancy way in PHP, but
> it just display blank screen. Can You please look at my code:

If it helps, here is some code that I dug up from an old project:



I would also verify that the web server has permissions to the files
that php is trying to open. Internet Explorer 8 seems to have a
problem with the filename parameter in the Content-disposition header
being enclosed in quotes. It would just dump the binary data in the
page when I was testing this.

Regards,
Ryan

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



Re: [PHP] downloading winword & mp3 files the fancy way through a browser

2009-08-26 Thread hack988 hack988
All IE has a bug for download file so.:)
see this http://support.microsoft.com/default.aspx?scid=kb;en-us;308090
some unkown mime type also display in IE no popup a download window

2009/8/26 Ryan Cavicchioni :
> On Wed, Aug 26, 2009 at 03:38:27PM +0200, Grega Leskov??ek wrote:
>> I tried to download the file from another server the fancy way in PHP, but
>> it just display blank screen. Can You please look at my code:
>
> If it helps, here is some code that I dug up from an old project:
>
> 
> $filepath = "/var/www/test.doc";
> $filename = basename($filepath);
> $filesize = filesize($filepath);
>
> if ( file_exists($filepath) )
> {
>    header("Cache-Control: no-store, must-revalidate");
>    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
>    header("Content-Transfer-Encoding: binary");
>    header("Content-Type: application/force-download");
>    header("Content-Type: application/octet-stream");
>    header("Content-Type: application/download");
>    header("Content-disposition: attachment; filename=" . $filename);
>    header("Content-length: " . $filesize);
>    $fh = fopen($filepath, "rb") or exit("Could not open file.");
>    while (!feof($fh))
>    {
>        print(fgets($fh,4096));
>    }
>    fclose($fh);
> } else {
>        echo "The file does not exist.";
> }
>
> ?>
>
> I would also verify that the web server has permissions to the files
> that php is trying to open. Internet Explorer 8 seems to have a
> problem with the filename parameter in the Content-disposition header
> being enclosed in quotes. It would just dump the binary data in the
> page when I was testing this.
>
> Regards,
> Ryan
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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