open($source, ZIPARCHIVE::CHECKCONS); if ($res !== true) { switch ($res) { case ZipArchive::ER_NOZIP: $msg = 'not a zip archive'; break; case ZipArchive::ER_INCONS: $msg = 'consistency check failed'; break; case ZipArchive::ER_CRC: $msg = 'checksum failed'; break; default: $msg = 'Bad Zip file'; } throw new common_Exception($msg); } else { $returnValue = true; } $zip->close(); return $returnValue; } public static function isValidQtiZip($source) { $returnValue = false; if (self::isValidZip($source)) { $zip = new ZipArchive(); $zip->open($source, ZIPARCHIVE::CHECKCONS); if ($zip->locateName("imsmanifest.xml") === false) { throw new common_Exception("A QTI package must contains a imsmanifest.xml file at the root of the archive"); } else { $returnValue = true; } $zip->close(); } return $returnValue; } }