private function _load_file_list_by_eof(&$fh, $stop_on_file = false)
{
// Check if there's a valid Central Dir signature.
// Let's consider a file comment smaller than 1024 characters...
// Actually, it length can be 65536.. But we're not going to support it.
for ($x = 0; $x < 1024; ++$x) {
fseek($fh, -22 - $x, SEEK_END);
$signature = fread($fh, 4);
if ($signature == $this->central_signature_end) {
// If found EOF Central Dir
$eodir['disk_number_this'] = unpack('v', fread($fh, 2));
// number of this disk
$eodir['disk_number'] = unpack('v', fread($fh, 2));
// number of the disk with the start of the central directory
$eodir['total_entries_this'] = unpack('v', fread($fh, 2));
// total number of entries in the central dir on this disk
$eodir['total_entries'] = unpack('v', fread($fh, 2));
// total number of entries in
$eodir['size_of_cd'] = unpack('V', fread($fh, 4));
// size of the central directory
$eodir['offset_start_cd'] = unpack('V', fread($fh, 4));
// offset of start of central directory with respect to the starting disk number
$zip_comment_lenght = unpack('v', fread($fh, 2));
// zipfile comment length
$eodir['zipfile_comment'] = $zip_comment_lenght[1] ? fread($fh, $zip_comment_lenght[1]) : '';
// zipfile comment
$this->end_of_central = array('disk_number_this' => $eodir['disk_number_this'][1], 'disk_number' => $eodir['disk_number'][1], 'total_entries_this' => $eodir['total_entries_this'][1], 'total_entries' => $eodir['total_entries'][1], 'size_of_cd' => $eodir['size_of_cd'][1], 'offset_start_cd' => $eodir['offset_start_cd'][1], 'zipfile_comment' => $eodir['zipfile_comment']);
// Then, load file list
fseek($fh, $this->end_of_central['offset_start_cd']);
$signature = fread($fh, 4);
while ($signature == $this->dir_signature) {
$dir['version_madeby'] = unpack('v', fread($fh, 2));
// version made by
$dir['version_needed'] = unpack('v', fread($fh, 2));
// version needed to extract
$dir['general_bit_flag'] = unpack('v', fread($fh, 2));
// general purpose bit flag
$dir['compression_method'] = unpack('v', fread($fh, 2));
// compression method
$dir['lastmod_time'] = unpack('v', fread($fh, 2));
// last mod file time
$dir['lastmod_date'] = unpack('v', fread($fh, 2));
// last mod file date
$dir['crc-32'] = fread($fh, 4);
// crc-32
$dir['compressed_size'] = unpack('V', fread($fh, 4));
// compressed size
$dir['uncompressed_size'] = unpack('V', fread($fh, 4));
// uncompressed size
$zip_file_length = unpack('v', fread($fh, 2));
// filename length
$extra_field_length = unpack('v', fread($fh, 2));
// extra field length
$fileCommentLength = unpack('v', fread($fh, 2));
// file comment length
$dir['disk_number_start'] = unpack('v', fread($fh, 2));
// disk number start
$dir['internal_attributes'] = unpack('v', fread($fh, 2));
// internal file attributes-byte1
$dir['external_attributes1'] = unpack('v', fread($fh, 2));
// external file attributes-byte2
$dir['external_attributes2'] = unpack('v', fread($fh, 2));
// external file attributes
$dir['relative_offset'] = unpack('V', fread($fh, 4));
// relative offset of local header
$dir['file_name'] = fread($fh, $zip_file_length[1]);
// filename
$dir['extra_field'] = $extra_field_length[1] ? fread($fh, $extra_field_length[1]) : '';
// extra field
$dir['file_comment'] = $fileCommentLength[1] ? fread($fh, $fileCommentLength[1]) : '';
// file comment
// Convert the date and time, from MS-DOS format to UNIX Timestamp
$binary_mod_date = str_pad(decbin($dir['lastmod_date'][1]), 16, '0', STR_PAD_LEFT);
$binary_mod_time = str_pad(decbin($dir['lastmod_time'][1]), 16, '0', STR_PAD_LEFT);
$last_mod_year = bindec(substr($binary_mod_date, 0, 7)) + 1980;
$last_mod_month = bindec(substr($binary_mod_date, 7, 4));
$last_mod_day = bindec(substr($binary_mod_date, 11, 5));
$last_mod_hour = bindec(substr($binary_mod_time, 0, 5));
$last_mod_minute = bindec(substr($binary_mod_time, 5, 6));
$last_mod_second = bindec(substr($binary_mod_time, 11, 5));
$this->central_dir_list[$dir['file_name']] = array('version_madeby' => $dir['version_madeby'][1], 'version_needed' => $dir['version_needed'][1], 'general_bit_flag' => str_pad(decbin($dir['general_bit_flag'][1]), 8, '0', STR_PAD_LEFT), 'compression_method' => $dir['compression_method'][1], 'lastmod_datetime' => mktime($last_mod_hour, $last_mod_minute, $last_mod_second, $last_mod_month, $last_mod_day, $last_mod_year), 'crc-32' => str_pad(dechex(ord($dir['crc-32'][3])), 2, '0', STR_PAD_LEFT) . str_pad(dechex(ord($dir['crc-32'][2])), 2, '0', STR_PAD_LEFT) . str_pad(dechex(ord($dir['crc-32'][1])), 2, '0', STR_PAD_LEFT) . str_pad(dechex(ord($dir['crc-32'][0])), 2, '0', STR_PAD_LEFT), 'compressed_size' => $dir['compressed_size'][1], 'uncompressed_size' => $dir['uncompressed_size'][1], 'disk_number_start' => $dir['disk_number_start'][1], 'internal_attributes' => $dir['internal_attributes'][1], 'external_attributes1' => $dir['external_attributes1'][1], 'external_attributes2' => $dir['external_attributes2'][1], 'relative_offset' => $dir['relative_offset'][1], 'file_name' => $dir['file_name'], 'extra_field' => $dir['extra_field'], 'file_comment' => $dir['file_comment']);
$signature = fread($fh, 4);
}
// If loaded centralDirs, then try to identify the offsetPosition of the compressed data.
if ($this->central_dir_list) {
foreach ($this->central_dir_list as $filename => $details) {
$i = $this->_get_file_header($fh, $details['relative_offset']);
$this->compressed_list[$filename]['file_name'] = $filename;
$this->compressed_list[$filename]['compression_method'] = $details['compression_method'];
$this->compressed_list[$filename]['version_needed'] = $details['version_needed'];
$this->compressed_list[$filename]['lastmod_datetime'] = $details['lastmod_datetime'];
$this->compressed_list[$filename]['crc-32'] = $details['crc-32'];
$this->compressed_list[$filename]['compressed_size'] = $details['compressed_size'];
$this->compressed_list[$filename]['uncompressed_size'] = $details['uncompressed_size'];
$this->compressed_list[$filename]['lastmod_datetime'] = $details['lastmod_datetime'];
$this->compressed_list[$filename]['extra_field'] = $i['extra_field'];
$this->compressed_list[$filename]['contents_start_offset'] = $i['contents_start_offset'];
if (strtolower($stop_on_file) == strtolower($filename)) {
break;
}
}
}
return true;
}
}
return false;
}