function PclZip::privAddFileUsingTempFile in Loft Data Grids 7.2
Same name and namespace in other branches
- 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php \PclZip::privAddFileUsingTempFile()
1 call to PclZip::privAddFileUsingTempFile()
- PclZip::privAddFile in vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php
File
- vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php, line 2798
Class
- PclZip
Code
function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) {
$v_result = PCLZIP_ERR_NO_ERROR;
$p_filename = $p_filedescr['filename'];
if (($v_file = @fopen($p_filename, "rb")) == 0) {
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '{$p_filename}' in binary read mode");
return PclZip::errorCode();
}
$v_gzip_temp_name = PCLZIP_TEMPORARY_DIR . uniqid('pclzip-') . '.gz';
if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
fclose($v_file);
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \'' . $v_gzip_temp_name . '\' in binary write mode');
return PclZip::errorCode();
}
$v_size = filesize($p_filename);
while ($v_size != 0) {
$v_read_size = $v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE;
$v_buffer = @fread($v_file, $v_read_size);
@gzputs($v_file_compressed, $v_buffer, $v_read_size);
$v_size -= $v_read_size;
}
@fclose($v_file);
@gzclose($v_file_compressed);
if (filesize($v_gzip_temp_name) < 18) {
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \'' . $v_gzip_temp_name . '\' has invalid filesize - should be minimum 18 bytes');
return PclZip::errorCode();
}
if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \'' . $v_gzip_temp_name . '\' in binary read mode');
return PclZip::errorCode();
}
$v_binary_data = @fread($v_file_compressed, 10);
$v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
$v_data_header['os'] = bin2hex($v_data_header['os']);
@fseek($v_file_compressed, filesize($v_gzip_temp_name) - 8);
$v_binary_data = @fread($v_file_compressed, 8);
$v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
$p_header['compression'] = ord($v_data_header['cm']);
$p_header['crc'] = $v_data_footer['crc'];
$p_header['compressed_size'] = filesize($v_gzip_temp_name) - 18;
@fclose($v_file_compressed);
if (($v_result = $this
->privWriteFileHeader($p_header)) != 1) {
return $v_result;
}
if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \'' . $v_gzip_temp_name . '\' in binary read mode');
return PclZip::errorCode();
}
fseek($v_file_compressed, 10);
$v_size = $p_header['compressed_size'];
while ($v_size != 0) {
$v_read_size = $v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE;
$v_buffer = @fread($v_file_compressed, $v_read_size);
@fwrite($this->zip_fd, $v_buffer, $v_read_size);
$v_size -= $v_read_size;
}
@fclose($v_file_compressed);
@unlink($v_gzip_temp_name);
return $v_result;
}