Jump to content

zip help


steviez

Recommended Posts

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

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

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

<?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

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.