181 public function create($p_filelist, $p_params=0)
186 if (0 === $p_params) {
191 'no_compression' =>
false,
194 'remove_all_path' =>
false
202 if (is_array($p_filelist)) {
203 $v_result = $this->
_create($p_filelist, $p_result_list, $p_params);
207 elseif (is_string($p_filelist)) {
209 $v_list = explode(ARCHIVE_ZIP_SEPARATOR, $p_filelist);
211 $v_result = $this->
_create($v_list, $p_result_list, $p_params);
216 $this->
_errorLog(ARCHIVE_ZIP_ERR_INVALID_PARAMETER,
217 'Invalid variable type p_filelist');
218 $v_result = ARCHIVE_ZIP_ERR_INVALID_PARAMETER;
221 if (1 != $v_result) {
225 return $p_result_list;
255 public function add($p_filelist, $p_params=0)
260 if (0 === $p_params) {
265 'no_compression' =>
false,
268 'remove_all_path' =>
false,
269 'callback_pre_add' =>
'',
270 'callback_post_add' =>
''
278 if (is_array($p_filelist)) {
280 $v_result = $this->
_add($p_filelist, $p_result_list, $p_params);
284 elseif (is_string($p_filelist)) {
286 $v_list = explode(ARCHIVE_ZIP_SEPARATOR, $p_filelist);
289 $v_result = $this->
_add($v_list, $p_result_list, $p_params);
294 $this->
_errorLog(ARCHIVE_ZIP_ERR_INVALID_PARAMETER,
295 'add() : Invalid variable type p_filelist'
297 $v_result = ARCHIVE_ZIP_ERR_INVALID_PARAMETER;
300 if (1 != $v_result) {
305 return $p_result_list;
1093 public function _addList($p_list, &$p_result_list,
1094 $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_params)
1098 // ----- Add the files
1099 $v_header_list = [];
1100 if (1 != ($v_result = $this->_addFileList($p_list, $v_header_list,
1101 $p_add_dir, $p_remove_dir,
1102 $p_remove_all_dir, $p_params))) {
1106 // ----- Store the offset of the central dir
1107 $v_offset = @ftell($this->_zip_fd);
1109 // ----- Create the Central Dir files header
1110 for ($i=0, $v_count=0; $i < count($v_header_list); $i++) {
1111 // ----- Create the file header
1112 if ('ok
' == $v_header_list[$i]['status
']) {
1113 if (1 != ($v_result = $this->_writeCentralFileHeader($v_header_list[$i]))) {
1119 // ----- Transform the header to a 'usable
' info
1120 $this->_convertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
1123 // ----- Zip file comment
1126 // ----- Calculate the size of the central header
1127 $v_size = @ftell($this->_zip_fd)-$v_offset;
1129 // ----- Create the central dir footer
1130 if (1 != ($v_result = $this->_writeCentralHeader($v_count, $v_size, $v_offset,
1132 // ----- Reset the file list
1133 unset($v_header_list);
1169 public function _addFileList($p_list, &$p_result_list,
1170 $p_add_dir, $p_remove_dir, $p_remove_all_dir,
1176 // ----- Recuperate the current number of elt in list
1177 $v_nb = count($p_result_list);
1179 // ----- Loop on the files
1180 for ($j=0; ($j<count($p_list)) && (1 == $v_result); $j++) {
1181 // ----- Recuperate the filename
1182 $p_filename = $this->_tool_TranslateWinPath($p_list[$j], false);
1184 // ----- Skip empty file names
1185 if ('
' == $p_filename) {
1189 // ----- Check the filename
1190 if (!file_exists($p_filename)) {
1191 $this->_errorLog(ARCHIVE_ZIP_ERR_MISSING_FILE,
1192 "File '$p_filename
' does not exists");
1193 return Archive_Zip::errorCode();
1196 // ----- Look if it is a file or a dir with no all pathnre move
1197 if ((is_file($p_filename)) || ((is_dir($p_filename)) && !$p_remove_all_dir)) {
1198 // ----- Add the file
1199 if (1 != ($v_result = $this->_addFile($p_filename, $v_header, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_params))) {
1200 // ----- Return status
1204 // ----- Store the file infos
1205 $p_result_list[$v_nb++] = $v_header;
1208 // ----- Look for directory
1209 if (is_dir($p_filename)) {
1211 // ----- Look for path
1212 if ('.
' != $p_filename) {
1213 $v_path = $p_filename . '/
';
1218 // ----- Read the directory for files and sub-directories
1219 $p_hdir = opendir($p_filename);
1220 $p_hitem = readdir($p_hdir); // '.
' directory
1221 $p_hitem = readdir($p_hdir); // '..
' directory
1222 while ($p_hitem = readdir($p_hdir)) {
1224 // ----- Look for a file
1225 if (is_file($v_path.$p_hitem)) {
1227 // ----- Add the file
1228 if (1 != ($v_result = $this->_addFile($v_path . $p_hitem, $v_header, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_params))) {
1229 // ----- Return status
1233 // ----- Store the file infos
1234 $p_result_list[$v_nb++] = $v_header;
1237 // ----- Recursive call to _addFileList()
1240 // ----- Need an array as parameter
1241 $p_temp_list[0] = $v_path.$p_hitem;
1242 $v_result = $this->_addFileList($p_temp_list, $p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_params);
1244 // ----- Update the number of elements of the list
1245 $v_nb = count($p_result_list);
1249 // ----- Free memory for the recursive loop
1250 unset($p_temp_list);
2000 public function _extractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_params)
2004 // ----- Read the file header
2005 if (1 != ($v_result = $this->_readFileHeader($v_header))) {
2011 // ----- Check that the file header is coherent with $p_entry info
2014 // ----- Look for all path to remove
2015 if (true == $p_remove_all_path) {
2016 // ----- Get the basename of the path
2017 $p_entry['filename
'] = basename($p_entry['filename
']);
2020 // ----- Look for path to remove
2021 elseif ('' != $p_remove_path) {
2022 //if (strcmp($p_remove_path, $p_entry['filename
'])==0)
2023 if (2 == $this->_tool_PathInclusion($p_remove_path, $p_entry['filename
'])) {
2025 // ----- Change the file status
2026 $p_entry['status
'] = 'filtered
';
2032 $p_remove_path_size = strlen($p_remove_path);
2033 if (substr($p_entry['filename
'], 0, $p_remove_path_size) == $p_remove_path) {
2035 // ----- Remove the path
2036 $p_entry['filename
'] = substr($p_entry['filename
'], $p_remove_path_size);
2040 // ----- Add the path
2041 if ('' != $p_path) {
2042 $p_entry['filename
'] = $p_path . '/
' . $p_entry['filename
'];
2045 // ----- Look for pre-extract callback
2046 if ((isset($p_params[ARCHIVE_ZIP_PARAM_PRE_EXTRACT]))
2047 && ('' != $p_params[ARCHIVE_ZIP_PARAM_PRE_EXTRACT])) {
2049 // ----- Generate a local information
2050 $v_local_header = [];
2051 $this->_convertHeader2FileInfo($p_entry, $v_local_header);
2053 // ----- Call the callback
2054 // Here I do not use call_user_func() because I need to send a reference to the
2056 eval('$v_result =
'.$p_params[ARCHIVE_ZIP_PARAM_PRE_EXTRACT].'(ARCHIVE_ZIP_PARAM_PRE_EXTRACT, $v_local_header);
');
2057 if (0 == $v_result) {
2058 // ----- Change the file status
2059 $p_entry['status
'] = 'skipped
';
2063 // ----- Update the informations
2064 // Only some fields can be modified
2065 $p_entry['filename
'] = $v_local_header['filename
'];
2070 // ----- Look if extraction should be done
2071 if ('ok
' == $p_entry['status
']) {
2073 // ----- Look for specific actions while the file exist
2074 if (file_exists($p_entry['filename
'])) {
2076 // ----- Look if file is a directory
2077 if (is_dir($p_entry['filename
'])) {
2079 // ----- Change the file status
2080 $p_entry['status
'] = 'already_a_directory
';
2085 // ----- Look if file is write protected
2086 elseif (!is_writable($p_entry['filename
'])) {
2088 // ----- Change the file status
2089 $p_entry['status
'] = 'write_protected
';
2095 // ----- Look if the extracted file is older
2096 elseif (filemtime($p_entry['filename
']) > $p_entry['mtime
']) {
2098 // ----- Change the file status
2099 $p_entry['status
'] = 'newer_exist
';
2106 // ----- Check the directory availability and create it if necessary
2108 if ((0x00000010 == ($p_entry['external
'] & 0x00000010)) || ('/
' == substr($p_entry['filename
'], -1))) {
2109 $v_dir_to_check = $p_entry['filename
'];
2110 } elseif (!strstr($p_entry['filename
'], '/
')) {
2111 $v_dir_to_check = '';
2113 $v_dir_to_check = dirname($p_entry['filename
']);
2116 if (1 != ($v_result = $this->_dirCheck($v_dir_to_check, (0x00000010 == ($p_entry['external
'] & 0x00000010))))) {
2118 // ----- Change the file status
2119 $p_entry['status
'] = 'path_creation_fail
';
2128 // ----- Look if extraction should be done
2129 if ('ok
' == $p_entry['status
']) {
2131 // ----- Do the extraction (if not a folder)
2132 if (!(0x00000010 == ($p_entry['external
'] & 0x00000010))) {
2134 // ----- Look for not compressed file
2135 if ($p_entry['compressed_size
'] == $p_entry['size
']) {
2137 // ----- Opening destination file
2138 if (0 == ($v_dest_file = @fopen($p_entry['filename
'], 'wb
'))) {
2140 // ----- Change the file status
2141 $p_entry['status
'] = 'write_error
';
2148 // ----- Read the file by ARCHIVE_ZIP_READ_BLOCK_SIZE octets blocks
2149 $v_size = $p_entry['compressed_size
'];
2150 while (0 != $v_size) {
2151 $v_read_size = ($v_size < ARCHIVE_ZIP_READ_BLOCK_SIZE ? $v_size : ARCHIVE_ZIP_READ_BLOCK_SIZE);
2152 $v_buffer = fread($this->_zip_fd, $v_read_size);
2153 $v_binary_data = pack('a
'.$v_read_size, $v_buffer);
2154 @fwrite($v_dest_file, $v_binary_data, $v_read_size);
2155 $v_size -= $v_read_size;
2158 // ----- Closing the destination file
2159 fclose($v_dest_file);
2161 // ----- Change the file mtime
2162 touch($p_entry['filename
'], $p_entry['mtime
']);
2166 // ----- Opening destination file
2167 if (0 == ($v_dest_file = @fopen($p_entry['filename
'], 'wb
'))) {
2169 // ----- Change the file status
2170 $p_entry['status
'] = 'write_error
';
2176 // ----- Read the compressed file in a buffer (one shot)
2177 $v_buffer = @fread($this->_zip_fd, $p_entry['compressed_size
']);
2179 // ----- Decompress the file
2180 $v_file_content = gzinflate($v_buffer);
2183 // ----- Write the uncompressed data
2184 @fwrite($v_dest_file, $v_file_content, $p_entry['size
']);
2185 unset($v_file_content);
2187 // ----- Closing the destination file
2188 @fclose($v_dest_file);
2190 // ----- Change the file mtime
2191 touch($p_entry['filename
'], $p_entry['mtime
']);
2194 // ----- Look for chmod option
2195 if ((isset($p_params[ARCHIVE_ZIP_PARAM_SET_CHMOD]))
2196 && (0 != $p_params[ARCHIVE_ZIP_PARAM_SET_CHMOD])) {
2198 // ----- Change the mode of the file
2199 chmod($p_entry['filename
'], $p_params[ARCHIVE_ZIP_PARAM_SET_CHMOD]);
2204 // ----- Look for post-extract callback
2205 if ((isset($p_params[ARCHIVE_ZIP_PARAM_POST_EXTRACT]))
2206 && ('' != $p_params[ARCHIVE_ZIP_PARAM_POST_EXTRACT])) {
2208 // ----- Generate a local information
2209 $v_local_header = [];
2210 $this->_convertHeader2FileInfo($p_entry, $v_local_header);
2212 // ----- Call the callback
2213 // Here I do not use call_user_func() because I need to send a reference to the
2215 eval('$v_result =
'.$p_params[ARCHIVE_ZIP_PARAM_POST_EXTRACT].'(ARCHIVE_ZIP_PARAM_POST_EXTRACT, $v_local_header);
');
2505 public function _readEndCentralDir(&$p_central_dir)
2509 // ----- Go to the end of the zip file
2510 $v_size = filesize($this->_zipname);
2511 @fseek($this->_zip_fd, $v_size);
2512 if (@ftell($this->_zip_fd) != $v_size) {
2513 $this->_errorLog(ARCHIVE_ZIP_ERR_BAD_FORMAT,
2514 'Unable to go to the end of the archive \
''
2515 .$this->_zipname.
'\'');
2524 @fseek($this->_zip_fd, $v_size-22);
2525 if (($v_pos = @ftell($this->_zip_fd)) != ($v_size-22)) {
2526 $this->_errorLog(ARCHIVE_ZIP_ERR_BAD_FORMAT,
2527 'Unable to seek back to the middle of the archive \''
2528 .$this->_zipname.
'\'');
2529 return Archive_Zip::errorCode();
2533 $v_binary_data = @fread($this->_zip_fd, 4);
2534 $v_data = unpack(
'Vid', $v_binary_data);
2537 if (0x06054b50 == $v_data[
'id']) {
2541 $v_pos = ftell($this->_zip_fd);
2546 $v_maximum_size = 65557;
2547 if ($v_maximum_size > $v_size) {
2548 $v_maximum_size = $v_size;
2550 @fseek($this->_zip_fd, $v_size-$v_maximum_size);
2551 if (@ftell($this->_zip_fd) != ($v_size-$v_maximum_size)) {
2552 $this->
_errorLog(ARCHIVE_ZIP_ERR_BAD_FORMAT,
2553 'Unable to seek back to the middle of the archive \''
2554 .$this->_zipname.
'\'');
2559 $v_pos = ftell($this->_zip_fd);
2560 $v_bytes = 0x00000000;
2561 while ($v_pos < $v_size) {
2563 $v_byte = @fread($this->_zip_fd, 1);
2566 $v_bytes = ($v_bytes << 8) | Ord($v_byte);
2569 if (0x504b0506 == $v_bytes) {
2578 if ($v_pos == $v_size) {
2579 $this->
_errorLog(ARCHIVE_ZIP_ERR_BAD_FORMAT,
2580 'Unable to find End of Central Dir Record signature'
2587 $v_binary_data = fread($this->_zip_fd, 18);
2590 if (18 != strlen($v_binary_data)) {
2591 $this->
_errorLog(ARCHIVE_ZIP_ERR_BAD_FORMAT,
2592 'Invalid End of Central Dir Record size : '
2593 . strlen($v_binary_data));
2598 $v_data = unpack(
'vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
2601 if (($v_pos + $v_data[
'comment_size'] + 18) != $v_size) {
2602 $this->
_errorLog(ARCHIVE_ZIP_ERR_BAD_FORMAT,
2603 'Fail to find the right signature'
2609 if (0 != $v_data[
'comment_size']) {
2610 $p_central_dir[
'comment'] = fread($this->_zip_fd, $v_data[
'comment_size']);
2612 $p_central_dir[
'comment'] =
'';
2615 $p_central_dir[
'entries'] = $v_data[
'entries'];
2616 $p_central_dir[
'disk_entries'] = $v_data[
'disk_entries'];
2617 $p_central_dir[
'offset'] = $v_data[
'offset'];
2618 $p_central_dir[
'size'] = $v_data[
'size'];
2619 $p_central_dir[
'disk'] = $v_data[
'disk'];
2620 $p_central_dir[
'disk_start'] = $v_data[
'disk_start'];
2644 $v_list_detail = [];
2647 if (1 != ($v_result=$this->
_openFd(
'rb'))) {
2653 $v_central_dir = [];
2660 @rewind($this->_zip_fd);
2664 $v_pos_entry = $v_central_dir[
'offset'];
2665 @rewind($this->_zip_fd);
2666 if (@fseek($this->_zip_fd, $v_pos_entry)) {
2670 $this->
_errorLog(ARCHIVE_ZIP_ERR_INVALID_ARCHIVE_ZIP,
2671 'Invalid archive size');
2676 $v_header_list = [];
2678 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir[
'entries']; $i++) {
2681 $v_header_list[$v_nb_extracted] = [];
2684 if (1 != $v_result) {
2692 $v_header_list[$v_nb_extracted][
'index'] = $i;
2698 if ((isset($p_params[ARCHIVE_ZIP_PARAM_BY_NAME]))
2699 && (0 != $p_params[ARCHIVE_ZIP_PARAM_BY_NAME])) {
2703 ($j < count($p_params[ARCHIVE_ZIP_PARAM_BY_NAME]))
2708 if (
'/' == substr($p_params[ARCHIVE_ZIP_PARAM_BY_NAME][$j], -1)) {
2711 if ((strlen($v_header_list[$v_nb_extracted][
'stored_filename']) > strlen($p_params[ARCHIVE_ZIP_PARAM_BY_NAME][$j]))
2712 && (substr($v_header_list[$v_nb_extracted][
'stored_filename'], 0, strlen($p_params[ARCHIVE_ZIP_PARAM_BY_NAME][$j])) == $p_params[ARCHIVE_ZIP_PARAM_BY_NAME][$j])) {
2714 } elseif ((0x00000010 == ($v_header_list[$v_nb_extracted][
'external'] & 0x00000010))
2715 && ($v_header_list[$v_nb_extracted][
'stored_filename'].
'/' == $p_params[ARCHIVE_ZIP_PARAM_BY_NAME][$j])) {
2720 elseif ($v_header_list[$v_nb_extracted][
'stored_filename']
2721 == $p_params[ARCHIVE_ZIP_PARAM_BY_NAME][$j]) {
2728 elseif ((isset($p_params[ARCHIVE_ZIP_PARAM_BY_EREG]))
2729 && (
'' != $p_params[ARCHIVE_ZIP_PARAM_BY_EREG])) {
2730 if (ereg($p_params[ARCHIVE_ZIP_PARAM_BY_EREG],
2731 $v_header_list[$v_nb_extracted][
'stored_filename'])) {
2737 elseif ((isset($p_params[ARCHIVE_ZIP_PARAM_BY_PREG]))
2738 && (
'' != $p_params[ARCHIVE_ZIP_PARAM_BY_PREG])) {
2739 if (preg_match($p_params[ARCHIVE_ZIP_PARAM_BY_PREG],
2740 $v_header_list[$v_nb_extracted][
'stored_filename'])) {
2746 elseif ((isset($p_params[ARCHIVE_ZIP_PARAM_BY_INDEX]))
2747 && (0 != $p_params[ARCHIVE_ZIP_PARAM_BY_INDEX])) {
2751 ($j < count($p_params[ARCHIVE_ZIP_PARAM_BY_INDEX]))
2754 if (($i>=$p_params[ARCHIVE_ZIP_PARAM_BY_INDEX][$j][
'start'])
2755 && ($i<=$p_params[ARCHIVE_ZIP_PARAM_BY_INDEX][$j][
'end'])) {
2758 if ($i>=$p_params[ARCHIVE_ZIP_PARAM_BY_INDEX][$j][
'end']) {
2762 if ($p_params[ARCHIVE_ZIP_PARAM_BY_INDEX][$j][
'start']>$i) {
2770 unset($v_header_list[$v_nb_extracted]);
2777 if ($v_nb_extracted > 0) {
2780 $v_zip_temp_name = ARCHIVE_ZIP_TEMPORARY_DIR.uniqid(
'archive_zip-')
2787 if (1 != ($v_result = $v_temp_zip->_openFd(
'wb'))) {
2795 for ($i=0; $i < count($v_header_list); $i++) {
2798 @rewind($this->_zip_fd);
2799 if (@fseek($this->_zip_fd, $v_header_list[$i][
'offset'])) {
2802 $v_temp_zip->_closeFd();
2803 @unlink($v_zip_temp_name);
2805 $this->
_errorLog(ARCHIVE_ZIP_ERR_INVALID_ARCHIVE_ZIP,
2806 'Invalid archive size');
2814 $v_temp_zip->_closeFd();
2815 @unlink($v_zip_temp_name);
2821 $v_result = $v_temp_zip->_writeFileHeader($v_header_list[$i]);
2822 if (1 != $v_result) {
2825 $v_temp_zip->_closeFd();
2826 @unlink($v_zip_temp_name);
2833 $v_temp_zip->_zip_fd,
2834 $v_header_list[$i][
'compressed_size']);
2835 if (1 != $v_result) {
2838 $v_temp_zip->_closeFd();
2839 @unlink($v_zip_temp_name);
2846 $v_offset = @ftell($v_temp_zip->_zip_fd);
2849 for ($i=0; $i < count($v_header_list); $i++) {
2851 $v_result=$v_temp_zip->_writeCentralFileHeader($v_header_list[$i]);
2852 if (1 != $v_result) {
2854 $v_temp_zip->_closeFd();
2856 @unlink($v_zip_temp_name);
2862 $v_temp_zip->_convertHeader2FileInfo($v_header_list[$i],
2863 $p_result_list[$i]);
2871 $v_size = @ftell($v_temp_zip->_zip_fd)-$v_offset;
2874 $v_result = $v_temp_zip->_writeCentralHeader(count($v_header_list),
2877 if (1 != $v_result) {
2879 unset($v_header_list);
2880 $v_temp_zip->_closeFd();
2882 @unlink($v_zip_temp_name);
2888 $v_temp_zip->_closeFd();
2893 @unlink($this->_zipname);
2898 $this->
_tool_Rename($v_zip_temp_name, $this->_zipname);
2987 if (!is_file($p_archive_to_add->_zipname)) {
2993 if (!is_file($this->_zipname)) {
2995 $v_result = $this->
_duplicate($p_archive_to_add->_zipname);
3001 if (1 != ($v_result=$this->
_openFd(
'rb'))) {
3006 $v_central_dir = [];
3013 @rewind($this->_zip_fd);
3016 if (1 != ($v_result=$p_archive_to_add->_openFd(
'rb'))) {
3022 $v_central_dir_to_add = [];
3023 $v_result = $p_archive_to_add->_readEndCentralDir($v_central_dir_to_add);
3024 if (1 != $v_result) {
3026 $p_archive_to_add->_closeFd();
3031 @rewind($p_archive_to_add->_zip_fd);
3034 $v_zip_temp_name = ARCHIVE_ZIP_TEMPORARY_DIR.uniqid(
'archive_zip-').
'.tmp';
3037 if (0 == ($v_zip_temp_fd = @fopen($v_zip_temp_name,
'wb'))) {
3039 $p_archive_to_add->_closeFd();
3040 $this->
_errorLog(ARCHIVE_ZIP_ERR_READ_OPEN_FAIL,
3041 'Unable to open temporary file \''
3042 .$v_zip_temp_name.
'\' in binary write mode
');
3043 return Archive_Zip::errorCode();
3046 // ----- Copy the files from the archive to the temporary file
3047 // TBC : Here I should better append the file and go back to erase the
3049 $v_size = $v_central_dir['offset
'];
3050 while (0 != $v_size) {
3051 $v_read_size = ($v_size < ARCHIVE_ZIP_READ_BLOCK_SIZE
3052 ? $v_size : ARCHIVE_ZIP_READ_BLOCK_SIZE);
3053 $v_buffer = fread($this->_zip_fd, $v_read_size);
3054 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
3055 $v_size -= $v_read_size;
3058 // ----- Copy the files from the archive_to_add into the temporary file
3059 $v_size = $v_central_dir_to_add['offset
'];
3060 while (0 != $v_size) {
3061 $v_read_size = ($v_size < ARCHIVE_ZIP_READ_BLOCK_SIZE
3062 ? $v_size : ARCHIVE_ZIP_READ_BLOCK_SIZE);
3063 $v_buffer = fread($p_archive_to_add->_zip_fd, $v_read_size);
3064 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
3065 $v_size -= $v_read_size;
3068 // ----- Store the offset of the central dir
3069 $v_offset = @ftell($v_zip_temp_fd);
3071 // ----- Copy the block of file headers from the old archive
3072 $v_size = $v_central_dir['size
'];
3073 while (0 != $v_size) {
3074 $v_read_size = ($v_size < ARCHIVE_ZIP_READ_BLOCK_SIZE
3075 ? $v_size : ARCHIVE_ZIP_READ_BLOCK_SIZE);
3076 $v_buffer = @fread($this->_zip_fd, $v_read_size);
3077 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
3078 $v_size -= $v_read_size;
3081 // ----- Copy the block of file headers from the archive_to_add
3082 $v_size = $v_central_dir_to_add['size
'];
3083 while (0 != $v_size) {
3084 $v_read_size = ($v_size < ARCHIVE_ZIP_READ_BLOCK_SIZE
3085 ? $v_size : ARCHIVE_ZIP_READ_BLOCK_SIZE);
3086 $v_buffer = @fread($p_archive_to_add->_zip_fd, $v_read_size);
3087 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
3088 $v_size -= $v_read_size;
3091 // ----- Zip file comment
3092 // TBC : I should merge the two comments
3095 // ----- Calculate the size of the (new) central header
3096 $v_size = @ftell($v_zip_temp_fd)-$v_offset;
3098 // ----- Swap the file descriptor
3099 // Here is a trick : I swap the temporary fd with the zip fd, in order to use
3100 // the following methods on the temporary fil and not the real archive fd
3101 $v_swap = $this->_zip_fd;
3102 $this->_zip_fd = $v_zip_temp_fd;
3103 $v_zip_temp_fd = $v_swap;
3105 // ----- Create the central dir footer
3106 if (1 != ($v_result = $this->_writeCentralHeader($v_central_dir['entries
']
3107 +$v_central_dir_to_add['entries
'],
3111 $p_archive_to_add->_closeFd();
3112 @fclose($v_zip_temp_fd);
3113 $this->_zip_fd = null;
3115 // ----- Reset the file list
3116 unset($v_header_list);
3122 // ----- Swap back the file descriptor
3123 $v_swap = $this->_zip_fd;
3124 $this->_zip_fd = $v_zip_temp_fd;
3125 $v_zip_temp_fd = $v_swap;
3129 $p_archive_to_add->_closeFd();
3131 // ----- Close the temporary file
3132 @fclose($v_zip_temp_fd);
3134 // ----- Delete the zip file
3135 // TBC : I should test the result ...
3136 @unlink($this->_zipname);
3138 // ----- Rename the temporary file
3139 // TBC : I should test the result ...
3140 //@rename($v_zip_temp_name, $this->_zipname);
3141 $this->_tool_Rename($v_zip_temp_name, $this->_zipname);
3221 public function _check_parameters(&$p_params, $p_default)
3224 // ----- Check that param is an array
3225 if (!is_array($p_params)) {
3226 $this->_errorLog(ARCHIVE_ZIP_ERR_INVALID_PARAMETER,
3227 'Unsupported parameter, waiting
for an array
');
3228 return Archive_Zip::errorCode();
3231 // ----- Check that all the params are valid
3232 for (reset($p_params); list($v_key, $v_value) = each($p_params);) {
3233 if (!isset($p_default[$v_key])) {
3234 $this->_errorLog(ARCHIVE_ZIP_ERR_INVALID_PARAMETER,
3235 'Unsupported parameter with key \
''.$v_key.
'\'');
3242 for (reset($p_default); list($v_key, $v_value) = each($p_default);) {
3243 if (!isset($p_params[$v_key])) {
3244 $p_params[$v_key] = $p_default[$v_key];
3249 $v_callback_list = [
3250 'callback_pre_add',
'callback_post_add',
3251 'callback_pre_extract',
'callback_post_extract'
3253 for ($i=0; $i < count($v_callback_list); $i++) {
3254 $v_key=$v_callback_list[$i];
3255 if ((isset($p_params[$v_key])) && (
'' != $p_params[$v_key])) {
3256 if (!function_exists($p_params[$v_key])) {
3257 $this->
_errorLog(ARCHIVE_ZIP_ERR_INVALID_PARAM_VALUE,
3258 "Callback '".$p_params[$v_key]
3259 .
"()' is not an existing function for "
3260 .
"parameter '".$v_key.
"'");
3464 while (0 != $p_size) {
3465 $v_read_size = ($p_size < ARCHIVE_ZIP_READ_BLOCK_SIZE
3466 ? $p_size : ARCHIVE_ZIP_READ_BLOCK_SIZE);
3467 $v_buffer = @fread($p_src, $v_read_size);
3468 @fwrite($p_dest, $v_buffer, $v_read_size);
3469 $p_size -= $v_read_size;
3471 } elseif (1 == $p_mode) {
3472 while (0 != $p_size) {
3473 $v_read_size = ($p_size < ARCHIVE_ZIP_READ_BLOCK_SIZE
3474 ? $p_size : ARCHIVE_ZIP_READ_BLOCK_SIZE);
3475 $v_buffer = @gzread($p_src, $v_read_size);
3476 @fwrite($p_dest, $v_buffer, $v_read_size);
3477 $p_size -= $v_read_size;
3479 } elseif (2 == $p_mode) {
3480 while (0 != $p_size) {
3481 $v_read_size = ($p_size < ARCHIVE_ZIP_READ_BLOCK_SIZE
3482 ? $p_size : ARCHIVE_ZIP_READ_BLOCK_SIZE);
3483 $v_buffer = @fread($p_src, $v_read_size);
3484 @gzwrite($p_dest, $v_buffer, $v_read_size);
3485 $p_size -= $v_read_size;
3487 } elseif (3 == $p_mode) {
3488 while (0 != $p_size) {
3489 $v_read_size = ($p_size < ARCHIVE_ZIP_READ_BLOCK_SIZE
3490 ? $p_size : ARCHIVE_ZIP_READ_BLOCK_SIZE);
3491 $v_buffer = @gzread($p_src, $v_read_size);
3492 @gzwrite($p_dest, $v_buffer, $v_read_size);
3493 $p_size -= $v_read_size;