Re: Download with header() - file corrupted

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

 



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

-- 
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