kra1978 Posted May 15, 2008 Share Posted May 15, 2008 Hello Everyone, I have a site where I can create .zip file using PHP programming on the server. It is working fine. On Server, PHP 5.2.3 is installed. It is working fine for last 6-7 months. Yesterday I needed to switch the site from existing to server to new dedicated server. New server has PHP 5.2.5 Now, I can create zip file on the new server without any problem. But when I try to download it form the website, it starts downloading and suddenly shows that download is completed and when I try to unzip file then it is giving error message that file is corrupted/damaged. Yes, it is really corrupted because it's size (KB) is only 5-10% of actual file size. I am using following code for downloading .zip file. ===================================== $str_filename=""; $str_filepath=""; $str_ext=""; $str_filename=trim($rs_download_file->fields("photosetfilename")); $str_filepath=trim($UPLOAD_ZIPFILE_PATH.$str_filename); header("Content-Type:application/octet-stream"); header("Content-Disposition:attachment;filename=".$str_filename); $fp=fopen($str_filepath,'rb'); header("Content-Length:".filesize($str_filepath)); fpassthru($fp); exit(); ===================================== Please help me as soon as possible because I am in real trouble. Thanks in advance, KRA Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/ Share on other sites More sharing options...
redarrow Posted May 15, 2008 Share Posted May 15, 2008 All you need to do is look at your old php.ini file settings and cross match with your new settings........ your code works so there a setting not set correctly in ur new php.ini file... Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541781 Share on other sites More sharing options...
kra1978 Posted May 15, 2008 Author Share Posted May 15, 2008 I checked all settings and they are same except one. output_buffering In old server, it is set output_buffering=4096 and in new server it is set output_buffering=no value Please let me know whether this may be problem Thanks again, KRA Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541790 Share on other sites More sharing options...
MadTechie Posted May 15, 2008 Share Posted May 15, 2008 first of all check the zip file is being created correctly and you can download via ftp without problems.. if possible is thier a link we can try (to view header data etc) Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541802 Share on other sites More sharing options...
kra1978 Posted May 15, 2008 Author Share Posted May 15, 2008 Yes, There is .zip file created successfully on the server and I also downloaded it using FTP and then unzip...it is working!!! Dedicated Server Providers are saying that you need to change the script. I am not sure whether PHP 5.2.3 and PHP 5.2.5 can have different scripts to download .zip file from the website. Please advice, KRA Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541807 Share on other sites More sharing options...
MadTechie Posted May 15, 2008 Share Posted May 15, 2008 theirs nothing in that code thats would be affect from the minor version upgrade. humm try this <?php $str_filename=""; $str_filepath=""; $str_ext=""; $str_filename=trim($rs_download_file->fields("photosetfilename")); $str_filepath=trim($UPLOAD_ZIPFILE_PATH.$str_filename); header("Content-Type:application/octet-stream"); header("Content-Disposition:attachment;filename=".$str_filename); //LITTLE TEST if(!file_exists($str_filepath)) { die("Bad file path~".$str_filepath); } //END $fp=fopen($str_filepath,'rb'); header("Content-Length:".filesize($str_filepath)); fpassthru($fp); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541820 Share on other sites More sharing options...
kra1978 Posted May 15, 2008 Author Share Posted May 15, 2008 The code you provided is not working. The file is downloaded only 152 KB each time instead of original 1.85 MB file size. I found following code from the internet. Please advice whether it can be helpful or not. ========================== $str_filename=""; $str_filepath=""; $str_ext=""; $str_filename=trim($rs_download_file->fields("photosetfilename")); $str_filepath=trim($UPLOAD_ZIPFILE_PATH.$str_filename); // $str_ext=getextension($str_filename); header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); // header("Cache-Control: private",false); // required for certain browsers header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream", FALSE); header("Content-Type: application/download", FALSE); // header("Content-Type:application/octet-stream"); header("Content-Disposition:attachment;filename=".$str_filename); header("Content-Transfer-Encoding: binary"); $fp=fopen($str_filepath,'rb'); header("Content-Length:".filesize($str_filepath)); fpassthru($fp); exit(); ========================== Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541842 Share on other sites More sharing options...
MadTechie Posted May 15, 2008 Share Posted May 15, 2008 can you post the 152 KB file (attached it). i have an idea Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541849 Share on other sites More sharing options...
kra1978 Posted May 15, 2008 Author Share Posted May 15, 2008 Ok. I have attached the 152 KB file here. Thanks, KRA [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541863 Share on other sites More sharing options...
MadTechie Posted May 15, 2008 Share Posted May 15, 2008 Okay well its a valid zip file, with the index of 2 files photo_1.jpg photo_2.jpg but its truncated (only has the first part of the file).. try this revised version <?php $str_filename=""; $str_filepath=""; $str_ext=""; $str_filename=trim($rs_download_file->fields("photosetfilename")); $str_filepath=trim($UPLOAD_ZIPFILE_PATH.$str_filename); header("Pragma: public"); header("Expires: 0"); // set expiration time header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=".basename($str_filename)); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($str_filepath)); readfile($str_filename); exit(); #$fp=fopen($str_filepath,'rb'); #fpassthru($fp); ?> Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541883 Share on other sites More sharing options...
kra1978 Posted May 15, 2008 Author Share Posted May 15, 2008 I have one thing to ask...Should I add any MIME types on the server for the code you just provided? Please advice. KRA Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541897 Share on other sites More sharing options...
MadTechie Posted May 15, 2008 Share Posted May 15, 2008 no need, the code should run fine as it, as a note readfile($str_filename); uses more memory but thats not the issule at the moment. Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541901 Share on other sites More sharing options...
kra1978 Posted May 15, 2008 Author Share Posted May 15, 2008 Ok, I tried the code and now it is downloading file of only 1 KB. Also I found following link. Can you please advice that whether it may be the issue? They are saying that it is the bug in PHP 5.2.5....please let me know. http://bugs.php.net/bug.php?id=43306&edit=2 Thanks for your all efforts KRA Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541906 Share on other sites More sharing options...
redarrow Posted May 15, 2008 Share Posted May 15, 2008 try this just posted to me from a friend that got the same setup as you........ <?php $filename = $_GET['file']; // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); // addition by Jorg Weske $file_extension = strtolower(substr(strrchr($filename,"."),1)); if( $filename == "" ) { echo "<html><title>eLouai's Download Script</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>"; exit; } elseif ( ! file_exists( $filename ) ) { echo "<html><title>eLouai's Download Script</title><body>ERROR: File not found. USE force-download.php?file=filepath</body></html>"; exit; }; switch( $file_extension ) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: $ctype"); // change, added quotes to allow spaces in filenames, by Rajkumar Singh header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541913 Share on other sites More sharing options...
MadTechie Posted May 15, 2008 Share Posted May 15, 2008 well PHP PHP 5.2.6 is out http://www.php.net/downloads.php in 5.2.1 their was a bug with the zip creation (thats why i asked about it) Theirs a bug in my script readfile($str_filename); should be readfile($str_filepath); Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-541922 Share on other sites More sharing options...
kra1978 Posted May 15, 2008 Author Share Posted May 15, 2008 It does work !!! I really thank you very very much for your constant help through out the problem solution. Thanks again, KRA Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-542008 Share on other sites More sharing options...
MadTechie Posted May 15, 2008 Share Posted May 15, 2008 happy to help:) can you click solved to close this thread (saves other having to read it, only to findout its solved) Quote Link to comment https://forums.phpfreaks.com/topic/105743-solved-please-help-urgent-zip-file-download-problem-using-php-525/#findComment-542016 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.