Last active
December 12, 2015 06:59
-
-
Save SeanJA/4733597 to your computer and use it in GitHub Desktop.
Test a zip archive from php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this zip file is not a zip file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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