Exemple #1
0
$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);
    if ($file === false) {
        cli_error('Invalid Zip file header structure: ' . $archive);
    }
    // Read local file header.
    fseek($fp, $file['local_offset']);
    $localfile = unpack('Vsig/vversion_req/vgeneral/vmethod/Vmodified/Vcrc/Vsize_compressed/Vsize/vname_length/vextra_length', fread($fp, 30));
    if ($localfile['sig'] !== 0x4034b50) {
        // Borked file!
        $file['error'] = 'Invalid local file signature';
        $files[] = $file;
        continue;
    }
    if ($localfile['name_length']) {
        $localfile['name'] = fread($fp, $localfile['name_length']);
    } else {