• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Zip: Unexpected end of archive

#1
[eluser]Unknown[/eluser]
Hi guys,

I'm writing a form page that requests contact details then allows a user to download a ZIP archive containing PDF documents, based on selections from a checkbox list. The ZIP file is creating and downloading fine, however when I open the file it comes back with the message 'Unexpected end of archive'.

Here's the code I'm using to generate the ZIP archive:

Code:
// Example of what form is passing to processing script.
$_POST['files'] = array(
  'products',
  'services'
);

$this->load->library('zip');

foreach ($_POST['files'] as $k => $v)
{
  // Make sure file exists before archiving.
  if (file_exists('/path/to/file/' . $v . '.pdf') === FALSE)
  {
    continue;
  }
                            
  $this->zip->read_file('/path/to/file/' . $v . '.pdf');
}

$this->zip->download('archive.zip');

I also have noticed that the modified dates in the archive are weird (i.e. 21/09/30032 12:51) if that helps.

Any insight into what I'm doing wrong or a solution to this problem would be great.

Thanks in advance.

#2
[eluser]Unknown[/eluser]
I believe I've found the problem with this and have reworked it to create a file on the server using zip->archive() instead.

Would I be right in thinking that the problem above can be caused when other data is sent to the header in addition to the zip->download() request? In other words, my code is basically like this:

Code:
function form()
{
  // Has form been submitted?
  if ($this->input->post('submit_button') !== FALSE)
  {
    // Validating and processing data...

    $this->zip->download('archive.zip');
  }

  // Fill data variable...

  $this->parser->parse('form', $data);
}

Because the form page is parsed after the ZIP has been downloaded, the header will be incorrect for the ZIP file. Not well explained, but I'd appreciate it if someone could confirm my reason.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.