4

I'm trying to unzip a file using PHP ZipArchive class but when I try:

$file = '/path/to/zip/file.zip';
$zip = new ZipArchive();
$res = $zip->open($file, ZipArchive::CHECKCONS);

The result is ZipArchive::ER_INCONS (Zip archive inconsistent)

Now, I've been able to open the zip file on my desktop (Windows 7) as well as using the bash command line tool unzip on the same box where the PHP application is running (Ubuntu 12.04). I am even able to unzip the file with in PHP using exec('unzip', $file);.

I have checked permissions for the cache folder and the zip file and the webserver has both read and write permission. I am able to open other zip file in the same directory with PHP's ZipArchive class.

I'm not sure if it is relevant, but the zip file I'm trying to open contains two zip files.

Any ideas as to why this may be happening?

grim
  • 6,669
  • 11
  • 38
  • 57
jdubu423
  • 405
  • 4
  • 18

1 Answers1

5

Turns out the file was being upload as ASCII, and I changed it to upload as binary.

jdubu423
  • 405
  • 4
  • 18
  • You are a lifesaver! How much time I have spend on changing the unzipping script, while it was actually the FTP file upload. How did you find it out? – Rick Apr 24 '20 at 17:38