function PclZip::privAdd 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::privAdd()
1 call to PclZip::privAdd()
- PclZip::add in vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php
File
- vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php, line 2159
Class
- PclZip
Code
function privAdd($p_filedescr_list, &$p_result_list, &$p_options) {
$v_result = 1;
$v_list_detail = array();
if (!is_file($this->zipname) || filesize($this->zipname) == 0) {
$v_result = $this
->privCreate($p_filedescr_list, $p_result_list, $p_options);
return $v_result;
}
$this
->privDisableMagicQuotes();
if (($v_result = $this
->privOpenFd('rb')) != 1) {
$this
->privSwapBackMagicQuotes();
return $v_result;
}
$v_central_dir = array();
if (($v_result = $this
->privReadEndCentralDir($v_central_dir)) != 1) {
$this
->privCloseFd();
$this
->privSwapBackMagicQuotes();
return $v_result;
}
@rewind($this->zip_fd);
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR . uniqid('pclzip-') . '.tmp';
if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) {
$this
->privCloseFd();
$this
->privSwapBackMagicQuotes();
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \'' . $v_zip_temp_name . '\' in binary write mode');
return PclZip::errorCode();
}
$v_size = $v_central_dir['offset'];
while ($v_size != 0) {
$v_read_size = $v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE;
$v_buffer = fread($this->zip_fd, $v_read_size);
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
$v_size -= $v_read_size;
}
$v_swap = $this->zip_fd;
$this->zip_fd = $v_zip_temp_fd;
$v_zip_temp_fd = $v_swap;
$v_header_list = array();
if (($v_result = $this
->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) {
fclose($v_zip_temp_fd);
$this
->privCloseFd();
@unlink($v_zip_temp_name);
$this
->privSwapBackMagicQuotes();
return $v_result;
}
$v_offset = @ftell($this->zip_fd);
$v_size = $v_central_dir['size'];
while ($v_size != 0) {
$v_read_size = $v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE;
$v_buffer = @fread($v_zip_temp_fd, $v_read_size);
@fwrite($this->zip_fd, $v_buffer, $v_read_size);
$v_size -= $v_read_size;
}
for ($i = 0, $v_count = 0; $i < sizeof($v_header_list); $i++) {
if ($v_header_list[$i]['status'] == 'ok') {
if (($v_result = $this
->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
fclose($v_zip_temp_fd);
$this
->privCloseFd();
@unlink($v_zip_temp_name);
$this
->privSwapBackMagicQuotes();
return $v_result;
}
$v_count++;
}
$this
->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
}
$v_comment = $v_central_dir['comment'];
if (isset($p_options[PCLZIP_OPT_COMMENT])) {
$v_comment = $p_options[PCLZIP_OPT_COMMENT];
}
if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
$v_comment = $v_comment . $p_options[PCLZIP_OPT_ADD_COMMENT];
}
if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
$v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT] . $v_comment;
}
$v_size = @ftell($this->zip_fd) - $v_offset;
if (($v_result = $this
->privWriteCentralHeader($v_count + $v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) {
unset($v_header_list);
$this
->privSwapBackMagicQuotes();
return $v_result;
}
$v_swap = $this->zip_fd;
$this->zip_fd = $v_zip_temp_fd;
$v_zip_temp_fd = $v_swap;
$this
->privCloseFd();
@fclose($v_zip_temp_fd);
$this
->privSwapBackMagicQuotes();
@unlink($this->zipname);
PclZipUtilRename($v_zip_temp_name, $this->zipname);
return $v_result;
}