Jump to content

Problem with zip file download


Samsam

Recommended Posts

hi phpfreaks!

 

i have a part of code which zips images files then allows zipped file to be downloaded.the zip works well but when forcing to download, it recognizes file size as 400 bytes and download corrupts.

i run my script on my pc(localhost)

 

may someone help me?

 

$data = implode("", file("myimage.jpg"));

$gzdata = gzencode($data, 9);

$fp = fopen("myimage.jpg.gz", "w");

fwrite($fp, $gzdata);

fclose($fp);

$file = "myimage.jpg.zip";


      header("Pragma: public");
      header("Expires: 0");
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
      header("Cache-Control: private",false);
      header ( "Content-Type: applicatio/zip" );
      header("Content-Disposition: attachment; filename=\"".$file."\";");
      header("Content-Length: " . filesize($file) ."; "); 
  
    readfile($file);

Link to comment
https://forums.phpfreaks.com/topic/206043-problem-with-zip-file-download/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.