problem forcing download on zip files
Posted: Fri Apr 29, 2005 3:30 pm
I'm encountering a strange problem with fopen/fpassthru && headers for downloading zip files. My dowload appears to be tru
ncated by 3 bytes. This happens with IE/Firefox and with firefox on Linux.
I have an application that stores files on the server (named as a hash). When user downloads a file (provided by database,
I rename the hash back to it's normal name, and read it to the browser and force-download.
This works great for images, word docs, etc, but zip files will produce the following error:
and in linux -> unzip:
I'm able to open the 'hashed' named file without a problem. The problem occurs after file has been renamed and downloaded.
Here is file listing showing the different file sizes:
These two are the same file. Notice the 'normal' named file is 3 bytes less than the hash'd named file.
When I use hexedit and cat a file with hexdumps of both files.. and diff them.. this is what I get:
< is hashed file
> is normal named file
So I'm missing 0000 in the final downloaded file.
Here is my code..
I've tried multipe methods.. including (fread, file_get_contents, and fpassthru). All result with the same truncated file length and unusable zip file.
Any help is greatly appreciated!
thanks
hanji
ncated by 3 bytes. This happens with IE/Firefox and with firefox on Linux.
I have an application that stores files on the server (named as a hash). When user downloads a file (provided by database,
I rename the hash back to it's normal name, and read it to the browser and force-download.
This works great for images, word docs, etc, but zip files will produce the following error:
Code: Select all
---------------------------
WinZip
---------------------------
Cannot open file: it does not appear to be a valid archive.
If you downloaded this file, try downloading the file again.Code: Select all
unzip testCounty.ZIP
Archive: testCounty.ZIP
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of testCounty.ZIP or
montCounty.ZIP.zip, and cannot find testCounty.ZIP.ZIP, period.I'm able to open the 'hashed' named file without a problem. The problem occurs after file has been renamed and downloaded.
Here is file listing showing the different file sizes:
Code: Select all
-rw-rw-r-- 1 hanji users 78276 Apr 29 11:42 4adddf640a2ca7568ebd1549d1978fa1
-rw-rw-r-- 1 hanji users 78273 Apr 29 11:42 testCounty.ZIPWhen I use hexedit and cat a file with hexdumps of both files.. and diff them.. this is what I get:
Code: Select all
4893,4894c4893,4894
< 00131c0 0001 0000
< 00131c4
---
> 00131c0 0001
> 00131c1> is normal named file
So I'm missing 0000 in the final downloaded file.
Here is my code..
Code: Select all
// $FileVal contains full path to 'hashed' file name
// $FileName is the 'normal' filename value
// make sure the file exists before sending headers
if(!$fdl=@fopen($FileVal,'rb')){
die("e;Cannot Open File!"e;);
} else {
header("e;Cache-Control: "e;);// leave blank to avoid IE errors
header("e;Pragma: "e;);// leave blank to avoid IE errors
header("e;Content-type: application/octet-stream"e;);
header("e;Content-Disposition: attachment; filename=\"e;"e;.$FileName."e;\"e;"e;);
header("e;Content-length:"e;.(string)(filesize($FileVal)));
@fpassthru($fdl);
}Any help is greatly appreciated!
thanks
hanji