Microweber\Utils\Unzip::_get_file_header PHP Method

_get_file_header() private method

--------------------------------------------------------------------
private _get_file_header ( &$fh, $start_offset = false )
    private function _get_file_header(&$fh, $start_offset = false)
    {
        if ($start_offset !== false) {
            fseek($fh, $start_offset);
        }
        $signature = fread($fh, 4);
        if ($signature == $this->zip_signature) {
            // Get information about the zipped file
            $file['version_needed'] = unpack('v', fread($fh, 2));
            // version needed to extract
            $file['general_bit_flag'] = unpack('v', fread($fh, 2));
            // general purpose bit flag
            $file['compression_method'] = unpack('v', fread($fh, 2));
            // compression method
            $file['lastmod_time'] = unpack('v', fread($fh, 2));
            // last mod file time
            $file['lastmod_date'] = unpack('v', fread($fh, 2));
            // last mod file date
            $file['crc-32'] = fread($fh, 4);
            // crc-32
            $file['compressed_size'] = unpack('V', fread($fh, 4));
            // compressed size
            $file['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
            $file['file_name'] = fread($fh, $zip_file_length[1]);
            // filename
            $file['extra_field'] = $extra_field_length[1] ? fread($fh, $extra_field_length[1]) : '';
            // extra field
            $file['contents_start_offset'] = ftell($fh);
            // Bypass the whole compressed contents, and look for the next file
            fseek($fh, $file['compressed_size'][1], SEEK_CUR);
            // Convert the date and time, from MS-DOS format to UNIX Timestamp
            $binary_mod_date = str_pad(decbin($file['lastmod_date'][1]), 16, '0', STR_PAD_LEFT);
            $binary_mod_time = str_pad(decbin($file['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));
            // Mount file table
            $i = array('file_name' => $file['file_name'], 'compression_method' => $file['compression_method'][1], 'version_needed' => $file['version_needed'][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($file['crc-32'][3])), 2, '0', STR_PAD_LEFT) . str_pad(dechex(ord($file['crc-32'][2])), 2, '0', STR_PAD_LEFT) . str_pad(dechex(ord($file['crc-32'][1])), 2, '0', STR_PAD_LEFT) . str_pad(dechex(ord($file['crc-32'][0])), 2, '0', STR_PAD_LEFT), 'compressed_size' => $file['compressed_size'][1], 'uncompressed_size' => $file['uncompressed_size'][1], 'extra_field' => $file['extra_field'], 'general_bit_flag' => str_pad(decbin($file['general_bit_flag'][1]), 8, '0', STR_PAD_LEFT), 'contents_start_offset' => $file['contents_start_offset']);
            return $i;
        }
        return false;
    }