steviez Posted May 20, 2009 Share Posted May 20, 2009 Hi, I am trying to zip up user files from a posted form, the form posts the file ids and then my script query's the database to get the file name. The only problem is that it only adds one file to the zip archive. Here is the code: <?php if(isset($_POST['file_option']) && $_POST['file_option'] == 'zip') { $files_array = $_POST['image_file']; // Move image foreach ($files_array as $f) { $r = sql_row("SELECT * FROM iv_uploads WHERE id = '".$f."'"); $filess = './uploads/' . $r['image_name']; $files = array($filess); create_zip($files, $username . '_images.zip', false); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-type: application/octet-stream"); header("Content-Type: application/download"); header("Content-disposition: attachment; filename=". $username . "_images.zip"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($username . "_images.zip")); readfile($username . "_images.zip"); } ?> any ideas? Link to comment https://forums.phpfreaks.com/topic/158984-zip-help/ Share on other sites More sharing options...
Masna Posted May 20, 2009 Share Posted May 20, 2009 Why are you putting everything in a loop? All of your header declarations should be outside of the loop. The only thing in the loop should be the readfile for each file (and whatever else you need to add each file to the .zip). Link to comment https://forums.phpfreaks.com/topic/158984-zip-help/#findComment-838467 Share on other sites More sharing options...
steviez Posted May 20, 2009 Author Share Posted May 20, 2009 Why are you putting everything in a loop? All of your header declarations should be outside of the loop. The only thing in the loop should be the readfile for each file (and whatever else you need to add each file to the .zip). my mistake, moved them out of the loop and it still dont work... Link to comment https://forums.phpfreaks.com/topic/158984-zip-help/#findComment-838471 Share on other sites More sharing options...
Masna Posted May 20, 2009 Share Posted May 20, 2009 Why are you putting everything in a loop? All of your header declarations should be outside of the loop. The only thing in the loop should be the readfile for each file (and whatever else you need to add each file to the .zip). my mistake, moved them out of the loop and it still dont work... Post your new code. Link to comment https://forums.phpfreaks.com/topic/158984-zip-help/#findComment-838477 Share on other sites More sharing options...
steviez Posted May 20, 2009 Author Share Posted May 20, 2009 <?php if(isset($_POST['file_option']) && $_POST['file_option'] == 'zip') { $files_array = $_POST['image_file']; // Move image foreach ($files_array as $f) { $r = sql_row("SELECT * FROM iv_uploads WHERE id = '".$f."'"); $filess = './uploads/' . $r['image_name']; $files = array($filess); } create_zip($files, $username . '_images.zip', false); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-type: application/octet-stream"); header("Content-Type: application/download"); header("Content-disposition: attachment; filename=". $username . "_images.zip"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($username . "_images.zip")); readfile($username . "_images.zip"); ?> Link to comment https://forums.phpfreaks.com/topic/158984-zip-help/#findComment-838480 Share on other sites More sharing options...
Masna Posted May 20, 2009 Share Posted May 20, 2009 Can we see the code for this mysterious create_zip function? Link to comment https://forums.phpfreaks.com/topic/158984-zip-help/#findComment-838482 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.