Reply to Re: [PHP] Download with header() - file corrupted

Your name:

Reply:


Posted by Richard Lynch on 03/02/05 20:37

Werner Jäger wrote:
> I try to download a file wit follow code:
>
> $len = filesize($file);
> $filename = basename($file);
> header("Pragma: public");
> header("Expires: 0");
> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> header("Cache-Control: public");

Is it kosher to have two Cache-Control headers?...

More important, do the browsers actually follow the spec if it *IS* kosher.

I'd sure try to get rid of one of these.

> header("Content-Description: File Transfer");
> header("Content-Type: $ctype");

What's $ctype?

It *SHOULD* be "application/octet-stream" if you want to force a download.

> $header="Content-Disposition: attachment; filename=".$filename.";";
> header($header );
> header("Content-Transfer-Encoding: binary");
> header("Content-Length: ".$len);
> readfile($file);
> exit;
>
>
> All works pretty well, the filename is correct, the Content Type and the
> file size.

Is $file a FULL pathname to the file, starting from /, such as:
/usr/home/full/path/to/file.txt

*NOT* just from DocumentRoot or the current directory?
While I would expect filesize and readfile to behave the same, I'd say
*always* use full path for both.

> When I try to open the downloaded file I see nothing.

I'm assuming the file size is not 0, which would mean that technically
everything is working fine, given what you have described :-)

> The source file on the web server works great.

If you want to force a download, use:
header("Content-type: application/octet-stream");

Every browser ever made knows that means "download"

> I played with Content-Transfer-Encoding and tried all values from the RFC

*WHICH* RFC?...

I gotta tell you, I've never had to use *THAT* many headers to get a
download.

Maybe you're just trying too hard, and using all the made-up headers of an
RFC that was never widely implemented/adopted... (Hint: If it was written
by Microsoft, it usually means only IE actually follows that "standard"
and there is usually a better pre-exsiting standard/RFC that everybody
else follows)

--
Like Music?
http://l-i-e.com/artists.htm

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация