Jump to content

[SOLVED] zip headers


networkthis

Recommended Posts

can anyone offer any guidance for creating headers that will allow for the download of a zip file to the browser window.  I have tried many different combos but keep getting corrupt data output on the screen or empty zip files.  I know the zip files are created properly because I can go directly to the page url, save them, unzip them and get all the files out in working form.

 

 

Link to comment
https://forums.phpfreaks.com/topic/111616-solved-zip-headers/
Share on other sites

Ok, I found the solution to my own problem

 

After trying many combinations of header functions nothing seemed to render the contents of any zip folder.  So, I finally discovered that I had to do something similar to the following....

 

<?php

//Display basic headers
header("Pragma: public");   
header("Expires: 0");   
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");   
header("Cache-Control: public");   
header("Content-Description: File Transfer");   
header("Content-Type: application/zip");   
header("Content-Disposition: attachment; filename=\"YOURzipFile.zip\"");  

//Open the file for streaming
$file = @fopen('YOURzipFile.zip',"rb");   
if ($file) {   
  while(!feof($file)) {   
    print(fread($file, 1024*);   
    flush();   
    if (connection_status()!=0) {   
      @fclose($file);   
      die();   
    }   
  }   
  @fclose($file);   
} 

?>

Link to comment
https://forums.phpfreaks.com/topic/111616-solved-zip-headers/#findComment-572993
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.