Skip to content

Instantly share code, notes, and snippets.

@SeanJA
Last active December 12, 2015 06:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeanJA/4733597 to your computer and use it in GitHub Desktop.
Save SeanJA/4733597 to your computer and use it in GitHub Desktop.
Test a zip archive from php
this zip file is not a zip file
<?php
class MyZipArchive extends ZipArchive{
/**
* Check a zip archive for problems
* @param string $filename
* @throws CorruptedZipFileException
*/
private function checkZip($filename){
$filename = escapeshellarg($filename);
$result = shell_exec('unzip -t ' . $filename);
if(strpos($result, 'No errors detected in compressed data') !== false){
throw new CorruptedZipFileException($result);
}
}
public function open ($filename, $flags = null) {
$this->checkZip($filename);
return parent::open($filename, $flags);
}
}
class CorruptedZipFileException extends Exception{}
$zip = new MyZipArchive();
$zip->open('/home/seanja/Downloads/currupted.zip');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment