Forum Moderators: coopster
$cfile = $_cpath.$_cd;
$type = "application/zip";
$size = @filesize($cfile);
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Transfer-Encoding: binary");
set_time_limit(0);
header("Content-Disposition: attachment; filename=$_cd");
header("Content-length: $size");
header("Content-type: $type");
@readfile($cfile) or die("File not found.");
exit;
Relative reading:
PDF downloads using readfile() [webmasterworld.com]
Download PDF documents [webmasterworld.com]
Annoying Header/File Name Problem [webmasterworld.com]
How prevent IE from adding [1] to name of a file passed by readfile()? [webmasterworld.com]
$cfile
$size
$type
come from?
are they posted? is it just a register_globals issue?
seems odd but if it isn't working then you need to look at configuration issues. As coop showed, most of this is controlled by the browser.
though it also seems strange sometimes the code shouldn't have worked and did, a server change sometimes brings this out, I know it shouldn't make sense but it does as I've seen it many times and have not been able to explain some of them.
I was on a shared host and now on my own VPS. Perhaps I have done something secure the VPS that causes this or it is a PHP configuration problem, I am not sure. I'm not even sure where to start to debug it.
The code btw is from the comments to the php site's "readfile" page.
Thanks for looking...
-----------------------------------------------------
[mysite.com...]
POST /myfile.php HTTP/1.1
Host: mysite.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: [mysite.com...]
Cookie: __utma=105385238.43134625.1209773928.1209773928.1209844734.2; __utmz=105385238.1209773928.1.1.utmccn=(direct)¦utmcsr=(direct)¦utmcmd=(none); __utmb=105385238; __utmc=105385238
Content-Type: application/x-www-form-urlencoded
Content-Length: 35
agreeterms=on&seccode=9&_download=1
HTTP/1.x 200 OK
Date: Sat, 03 May 2008 19:59:08 GMT
Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8b mod_auth_passthrough/2.1 mod_bwlimited/1.4
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
----------------------------------------------------------
zlib
ZLib Support enabled
Compiled Version 1.2.0.7
Linked Version 1.2.1.2
If you don't, I believe that would mess up the header enough to cause the problem you are seeing.
Zlib zlib.output_compression Off
Zlib zlib.output_handler **DEFAULT**, Click to Edit
I'm assuming it is ok?