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
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).

Link to comment
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.