downloading winword & mp3 files the fancy way through a browser

downloading winword & mp3 files the fancy way through a browser

am 26.08.2009 15:38:27 von legrega

--0015175cdb1ae4412004720b905c
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

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://aaaaaa.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

--0015175cdb1ae4412004720b905c--

Re: downloading winword & mp3 files the fancy way through a

am 26.08.2009 16:09:53 von 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://aaaaaa.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: downloading winword & mp3 files the fancy way through abrowser

am 26.08.2009 16:57:28 von List Manager

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://aaaaaa.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
$filepath = "http://aaaaaa.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: downloading winword & mp3 files the fancy way through a

am 26.08.2009 17:09:46 von 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

Re: downloading winword & mp3 files the fancy way through a

am 26.08.2009 17:20:13 von hack988 hack988

All IE has a bug for download file so.:)
see this http://support.microsoft.com/default.aspx?scid=3Dkb;en-us;30 8090
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, b=
ut
>> 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 =3D "/var/www/test.doc";
> $filename =3D basename($filepath);
> $filesize =3D filesize($filepath);
>
> if ( file_exists($filepath) )
> {
> =A0 =A0header("Cache-Control: no-store, must-revalidate");
> =A0 =A0header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
> =A0 =A0header("Content-Transfer-Encoding: binary");
> =A0 =A0header("Content-Type: application/force-download");
> =A0 =A0header("Content-Type: application/octet-stream");
> =A0 =A0header("Content-Type: application/download");
> =A0 =A0header("Content-disposition: attachment; filename=3D" . $filename)=
;
> =A0 =A0header("Content-length: " . $filesize);
> =A0 =A0$fh =3D fopen($filepath, "rb") or exit("Could not open file.");
> =A0 =A0while (!feof($fh))
> =A0 =A0{
> =A0 =A0 =A0 =A0print(fgets($fh,4096));
> =A0 =A0}
> =A0 =A0fclose($fh);
> } else {
> =A0 =A0 =A0 =A0echo "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