Welcome Guest, Not a member yet? Register   Sign In
GZip Uploaded File and then server it back up again on the fly
#1

[eluser]Unknown[/eluser]
I'm in the following situation. A person uploads a file and the system automatically gzips up the file using the following code:

Code:
$file_data = implode("",file($file_path.$uncomp_filename));
$gzdata = gzencode($file_data,9);
$compressed_file = fopen($file_path.$comp_filename,"w");
fwrite($compressed_file,$gzdata);
fclose($compressed_file);

The above works to create a valid gzip file. If I download the file and extract it, everything comes out as it should...

When a user wants to download their file they uploaded, the system "serves" the file to them. The system grabs the *.gz file on the server and unpacks it on the fly, and serves the unpacked file out to the user... This is the code to unpack the file:

Code:
$gzdata = gzopen($file_path.$comp_filename,"r");
$uncompressed_file = fopen($file_path.$uncomp_filename,"w");
while($line = gzgets($gzdata,4096))
{
  fwrite($uncompressed_file,$line);    
}    
fclose($uncompressed_file);
gzclose($gzdata);

I then do a readfile($uncompressed_file) to read the file out to the browser (with the appropriate headers sent first!). The problem is that the readfile (or even if I bypass the uncompress code and do a readgzfile) it adds some extra bytes which basically makes the file unreadable to msword, excel, etc... But if I just extract the file to the server directly and then download and read the file, it opens fine... It seems that the readfile (or readgzfile) is adding the extra content to the file which is making it unreadable. Any help is greatly appreciated!!!!!




Theme © iAndrew 2016 - Forum software by © MyBB