networkthis Posted June 24, 2008 Share Posted June 24, 2008 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 More sharing options...
gijew Posted June 24, 2008 Share Posted June 24, 2008 header('Content-Type: application/zip'); but if that fails you can default back to octet/strem Link to comment https://forums.phpfreaks.com/topic/111616-solved-zip-headers/#findComment-572949 Share on other sites More sharing options...
networkthis Posted June 24, 2008 Author Share Posted June 24, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.