Exemple #1
0
if (count($_SERVER['argv']) != 2 or !file_exists($_SERVER['argv'][1])) {
    cli_error("This script expects zip file name as the only parameter");
}
$archive = $_SERVER['argv'][1];
// Note: the ZIP structure is described at http://www.pkware.com/documents/casestudies/APPNOTE.TXT
if (!($filesize = filesize($archive)) or !($fp = fopen($archive, 'rb+'))) {
    cli_error("Can not open file file {$archive}");
}
fseek($fp, 0);
$info = unpack('Vsig', fread($fp, 4));
if ($info['sig'] !== 0x4034b50) {
    fclose($fp);
    cli_error("This is not a zip file: {$archive}");
}
// Find end of central directory record.
$centralend = zip_archive::zip_get_central_end($fp, $filesize);
if ($centralend === false) {
    cli_error("This is not a ZIP archive: {$archive}");
}
if ($centralend['disk'] !== 0 or $centralend['disk_start'] !== 0) {
    cli_error("Multi-disk archives are not supported: {$archive}");
}
if ($centralend['offset'] === 4294967295.0) {
    cli_error("ZIP64 archives are not supported: {$archive}");
}
fseek($fp, $centralend['offset']);
$data = fread($fp, $centralend['size']);
$pos = 0;
$files = array();
for ($i = 0; $i < $centralend['entries']; $i++) {
    $file = zip_archive::zip_parse_file_header($data, $centralend, $pos);