Search code examples
phpbashphp-ziparchive

Ziparchive unable to open zip file only in PHP


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?


Solution

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