Contao\ZipWriter::addString PHP Method

addString() public method

Add a file from a string to the archive
public addString ( string $strData, string $strName, integer $intTime )
$strData string The data to be added
$strName string The file path
$intTime integer An optional modification timestamp
    public function addString($strData, $strName, $intTime = 0)
    {
        ++$this->intCount;
        $strName = strtr($strName, '\\', '/');
        // Start file
        $arrFile['file_signature'] = self::FILE_SIGNATURE;
        $arrFile['version_needed_to_extract'] = "";
        $arrFile['general_purpose_bit_flag'] = "";
        $arrFile['compression_method'] = "";
        $arrFile['last_mod_file_hex'] = $this->unixToHex($intTime);
        $arrFile['crc-32'] = pack('V', crc32($strData));
        $intUncompressed = strlen($strData);
        // Compress data
        $strData = gzcompress($strData);
        $strData = substr(substr($strData, 0, strlen($strData) - 4), 2);
        $intCompressed = strlen($strData);
        // Continue file
        $arrFile['compressed_size'] = pack('V', $intCompressed);
        $arrFile['uncompressed_size'] = pack('V', $intUncompressed);
        $arrFile['file_name_length'] = pack('v', strlen($strName));
        $arrFile['extra_field_length'] = "";
        $arrFile['file_name'] = $strName;
        $arrFile['extra_field'] = '';
        // Store file offset
        $intOffset = @ftell($this->resFile);
        // Add file to archive
        fputs($this->resFile, implode('', $arrFile));
        fputs($this->resFile, $strData);
        // Start central directory
        $arrHeader['header_signature'] = self::CENTRAL_DIR_START;
        $arrHeader['version_made_by'] = "";
        $arrHeader['version_needed_to_extract'] = $arrFile['version_needed_to_extract'];
        $arrHeader['general_purpose_bit_flag'] = $arrFile['general_purpose_bit_flag'];
        $arrHeader['compression_method'] = $arrFile['compression_method'];
        $arrHeader['last_mod_file_hex'] = $arrFile['last_mod_file_hex'];
        $arrHeader['crc-32'] = $arrFile['crc-32'];
        $arrHeader['compressed_size'] = $arrFile['compressed_size'];
        $arrHeader['uncompressed_size'] = $arrFile['uncompressed_size'];
        $arrHeader['file_name_length'] = $arrFile['file_name_length'];
        $arrHeader['extra_field_length'] = $arrFile['extra_field_length'];
        $arrHeader['file_comment_length'] = "";
        $arrHeader['disk_number_start'] = "";
        $arrHeader['internal_file_attributes'] = "";
        $arrHeader['external_file_attributes'] = pack('V', 32);
        $arrHeader['offset_of_local_header'] = pack('V', $intOffset);
        $arrHeader['file_name'] = $arrFile['file_name'];
        $arrHeader['extra_field'] = $arrFile['extra_field'];
        $arrHeader['file_comment'] = '';
        // Add entry to central directory
        $this->strCentralDir .= implode('', $arrHeader);
    }