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? Quote Link to comment 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). Quote Link to comment 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... Quote Link to comment 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. Quote Link to comment 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"); ?> Quote Link to comment 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? Quote Link to comment 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.