Ffm.php 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  1. <?php
  2. if (!defined('BASEPATH')) exit('No direct script access allowed');
  3. if (!defined('PCLZIP_READ_BLOCK_SIZE')) {
  4. define('PCLZIP_READ_BLOCK_SIZE', 2048);
  5. }
  6. if (!defined('PCLZIP_SEPARATOR')) {
  7. define('PCLZIP_SEPARATOR', ',');
  8. }
  9. if (!defined('PCLZIP_ERROR_EXTERNAL')) {
  10. define('PCLZIP_ERROR_EXTERNAL', 0);
  11. }
  12. if (!defined('PCLZIP_TEMPORARY_DIR')) {
  13. define('PCLZIP_TEMPORARY_DIR', '');
  14. }
  15. if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) {
  16. define('PCLZIP_TEMPORARY_FILE_RATIO', 0.47);
  17. }
  18. $g_pclzip_version = "2.8.2";
  19. define('PCLZIP_ERR_USER_ABORTED', 2);
  20. define('PCLZIP_ERR_NO_ERROR', 0);
  21. define('PCLZIP_ERR_WRITE_OPEN_FAIL', -1);
  22. define('PCLZIP_ERR_READ_OPEN_FAIL', -2);
  23. define('PCLZIP_ERR_INVALID_PARAMETER', -3);
  24. define('PCLZIP_ERR_MISSING_FILE', -4);
  25. define('PCLZIP_ERR_FILENAME_TOO_LONG', -5);
  26. define('PCLZIP_ERR_INVALID_ZIP', -6);
  27. define('PCLZIP_ERR_BAD_EXTRACTED_FILE', -7);
  28. define('PCLZIP_ERR_DIR_CREATE_FAIL', -8);
  29. define('PCLZIP_ERR_BAD_EXTENSION', -9);
  30. define('PCLZIP_ERR_BAD_FORMAT', -10);
  31. define('PCLZIP_ERR_DELETE_FILE_FAIL', -11);
  32. define('PCLZIP_ERR_RENAME_FILE_FAIL', -12);
  33. define('PCLZIP_ERR_BAD_CHECKSUM', -13);
  34. define('PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14);
  35. define('PCLZIP_ERR_MISSING_OPTION_VALUE', -15);
  36. define('PCLZIP_ERR_INVALID_OPTION_VALUE', -16);
  37. define('PCLZIP_ERR_ALREADY_A_DIRECTORY', -17);
  38. define('PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18);
  39. define('PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19);
  40. define('PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20);
  41. define('PCLZIP_ERR_DIRECTORY_RESTRICTION', -21);
  42. define('PCLZIP_OPT_PATH', 77001);
  43. define('PCLZIP_OPT_ADD_PATH', 77002);
  44. define('PCLZIP_OPT_REMOVE_PATH', 77003);
  45. define('PCLZIP_OPT_REMOVE_ALL_PATH', 77004);
  46. define('PCLZIP_OPT_SET_CHMOD', 77005);
  47. define('PCLZIP_OPT_EXTRACT_AS_STRING', 77006);
  48. define('PCLZIP_OPT_NO_COMPRESSION', 77007);
  49. define('PCLZIP_OPT_BY_NAME', 77008);
  50. define('PCLZIP_OPT_BY_INDEX', 77009);
  51. define('PCLZIP_OPT_BY_EREG', 77010);
  52. define('PCLZIP_OPT_BY_PREG', 77011);
  53. define('PCLZIP_OPT_COMMENT', 77012);
  54. define('PCLZIP_OPT_ADD_COMMENT', 77013);
  55. define('PCLZIP_OPT_PREPEND_COMMENT', 77014);
  56. define('PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015);
  57. define('PCLZIP_OPT_REPLACE_NEWER', 77016);
  58. define('PCLZIP_OPT_STOP_ON_ERROR', 77017);
  59. define('PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019);
  60. define('PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020);
  61. define('PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020);
  62. define('PCLZIP_OPT_TEMP_FILE_ON', 77021);
  63. define('PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021);
  64. define('PCLZIP_OPT_TEMP_FILE_OFF', 77022);
  65. define('PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022);
  66. define('PCLZIP_ATT_FILE_NAME', 79001);
  67. define('PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002);
  68. define('PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003);
  69. define('PCLZIP_ATT_FILE_MTIME', 79004);
  70. define('PCLZIP_ATT_FILE_CONTENT', 79005);
  71. define('PCLZIP_ATT_FILE_COMMENT', 79006);
  72. define('PCLZIP_CB_PRE_EXTRACT', 78001);
  73. define('PCLZIP_CB_POST_EXTRACT', 78002);
  74. define('PCLZIP_CB_PRE_ADD', 78003);
  75. define('PCLZIP_CB_POST_ADD', 78004);
  76. class Ctzip
  77. {
  78. var $zipname = '';
  79. var $zip_fd = 0;
  80. var $error_code = 1;
  81. var $error_string = '';
  82. var $magic_quotes_status;
  83. function PclZip($p_zipname)
  84. {
  85. if (!function_exists('gzopen')) {
  86. die('Abort ' . basename(preg_replace('@\(.*\(.*$@', '', __FILE__)) . ' : Missing zlib extensions');
  87. }
  88. $this->zipname = $p_zipname;
  89. $this->zip_fd = 0;
  90. $this->magic_quotes_status = -1;
  91. return;
  92. }
  93. function delete()
  94. {
  95. $v_result = 1;
  96. $this->privErrorReset();
  97. if (!$this->privCheckFormat()) {
  98. return (0);
  99. }
  100. $v_options = array();
  101. $v_size = func_num_args();
  102. if ($v_size > 0) {
  103. $v_arg_list = func_get_args();
  104. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array(PCLZIP_OPT_BY_NAME => 'optional', PCLZIP_OPT_BY_EREG => 'optional', PCLZIP_OPT_BY_PREG => 'optional', PCLZIP_OPT_BY_INDEX => 'optional'));
  105. if ($v_result != 1) {
  106. return 0;
  107. }
  108. }
  109. $this->privDisableMagicQuotes();
  110. $v_list = array();
  111. if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
  112. $this->privSwapBackMagicQuotes();
  113. unset($v_list);
  114. return (0);
  115. }
  116. $this->privSwapBackMagicQuotes();
  117. return $v_list;
  118. }
  119. function deleteByIndex($p_index)
  120. {
  121. $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
  122. return $p_list;
  123. }
  124. function properties()
  125. {
  126. $this->privErrorReset();
  127. $this->privDisableMagicQuotes();
  128. if (!$this->privCheckFormat()) {
  129. $this->privSwapBackMagicQuotes();
  130. return (0);
  131. }
  132. $v_prop = array();
  133. $v_prop['comment'] = '';
  134. $v_prop['nb'] = 0;
  135. $v_prop['status'] = 'not_exist';
  136. if (@is_file($this->zipname)) {
  137. if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) {
  138. $this->privSwapBackMagicQuotes();
  139. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \'' . $this->zipname . '\' in binary read mode');
  140. return 0;
  141. }
  142. $v_central_dir = array();
  143. if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
  144. $this->privSwapBackMagicQuotes();
  145. return 0;
  146. }
  147. $this->privCloseFd();
  148. $v_prop['comment'] = $v_central_dir['comment'];
  149. $v_prop['nb'] = $v_central_dir['entries'];
  150. $v_prop['status'] = 'ok';
  151. }
  152. $this->privSwapBackMagicQuotes();
  153. return $v_prop;
  154. }
  155. function duplicate($p_archive)
  156. {
  157. $v_result = 1;
  158. $this->privErrorReset();
  159. if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) {
  160. $v_result = $this->privDuplicate($p_archive->zipname);
  161. } else if (is_string($p_archive)) {
  162. if (!is_file($p_archive)) {
  163. PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '" . $p_archive . "'");
  164. $v_result = PCLZIP_ERR_MISSING_FILE;
  165. } else {
  166. $v_result = $this->privDuplicate($p_archive);
  167. }
  168. } else {
  169. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 'Invalid variable type p_archive_to_add');
  170. $v_result = PCLZIP_ERR_INVALID_PARAMETER;
  171. }
  172. return $v_result;
  173. }
  174. function merge($p_archive_to_add)
  175. {
  176. $v_result = 1;
  177. $this->privErrorReset();
  178. if (!$this->privCheckFormat()) {
  179. return (0);
  180. }
  181. if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) {
  182. $v_result = $this->privMerge($p_archive_to_add);
  183. } else if (is_string($p_archive_to_add)) {
  184. $v_object_archive = new PclZip($p_archive_to_add);
  185. $v_result = $this->privMerge($v_object_archive);
  186. } else {
  187. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 'Invalid variable type p_archive_to_add');
  188. $v_result = PCLZIP_ERR_INVALID_PARAMETER;
  189. }
  190. return $v_result;
  191. }
  192. function errorCode()
  193. {
  194. if (PCLZIP_ERROR_EXTERNAL == 1) {
  195. return (PclErrorCode());
  196. } else {
  197. return ($this->error_code);
  198. }
  199. }
  200. function errorName($p_with_code = false)
  201. {
  202. $v_name = array(PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL', PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL', PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER', PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE', PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG', PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP', PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE', PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL', PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION', PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT', PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL', PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL', PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM', PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE', PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE', PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION');
  203. if (isset($v_name[$this->error_code])) {
  204. $v_value = $v_name[$this->error_code];
  205. } else {
  206. $v_value = 'NoName';
  207. }
  208. if ($p_with_code) {
  209. return ($v_value . ' (' . $this->error_code . ')');
  210. } else {
  211. return ($v_value);
  212. }
  213. }
  214. function errorInfo($p_full = false)
  215. {
  216. if (PCLZIP_ERROR_EXTERNAL == 1) {
  217. return (PclErrorString());
  218. } else {
  219. if ($p_full) {
  220. return ($this->errorName(true) . " : " . $this->error_string);
  221. } else {
  222. return ($this->error_string . " [code " . $this->error_code . "]");
  223. }
  224. }
  225. }
  226. function privCheckFormat($p_level = 0)
  227. {
  228. $v_result = true;
  229. clearstatcache();
  230. $this->privErrorReset();
  231. if (!is_file($this->zipname)) {
  232. PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '" . $this->zipname . "'");
  233. return (false);
  234. }
  235. if (!is_readable($this->zipname)) {
  236. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '" . $this->zipname . "'");
  237. return (false);
  238. }
  239. return $v_result;
  240. }
  241. function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options = false)
  242. {
  243. $v_result = 1;
  244. $i = 0;
  245. while ($i < $p_size) {
  246. if (!isset($v_requested_options[$p_options_list[$i]])) {
  247. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '" . $p_options_list[$i] . "' for this method");
  248. return PclZip::errorCode();
  249. }
  250. switch ($p_options_list[$i]) {
  251. case PCLZIP_OPT_PATH :
  252. case PCLZIP_OPT_REMOVE_PATH :
  253. case PCLZIP_OPT_ADD_PATH :
  254. if (($i + 1) >= $p_size) {
  255. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'");
  256. return PclZip::errorCode();
  257. }
  258. $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i + 1], FALSE);
  259. $i++;
  260. break;
  261. case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
  262. if (($i + 1) >= $p_size) {
  263. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'");
  264. return PclZip::errorCode();
  265. }
  266. if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
  267. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '" . PclZipUtilOptionText($p_options_list[$i]) . "' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
  268. return PclZip::errorCode();
  269. }
  270. $v_value = $p_options_list[$i + 1];
  271. if ((!is_integer($v_value)) || ($v_value < 0)) {
  272. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'");
  273. return PclZip::errorCode();
  274. }
  275. $v_result_list[$p_options_list[$i]] = $v_value * 1048576;
  276. $i++;
  277. break;
  278. case PCLZIP_OPT_TEMP_FILE_ON :
  279. if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
  280. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '" . PclZipUtilOptionText($p_options_list[$i]) . "' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
  281. return PclZip::errorCode();
  282. }
  283. $v_result_list[$p_options_list[$i]] = true;
  284. break;
  285. case PCLZIP_OPT_TEMP_FILE_OFF :
  286. if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
  287. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '" . PclZipUtilOptionText($p_options_list[$i]) . "' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
  288. return PclZip::errorCode();
  289. }
  290. if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
  291. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '" . PclZipUtilOptionText($p_options_list[$i]) . "' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
  292. return PclZip::errorCode();
  293. }
  294. $v_result_list[$p_options_list[$i]] = true;
  295. break;
  296. case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
  297. if (($i + 1) >= $p_size) {
  298. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'");
  299. return PclZip::errorCode();
  300. }
  301. if (is_string($p_options_list[$i + 1]) && ($p_options_list[$i + 1] != '')) {
  302. $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i + 1], FALSE);
  303. $i++;
  304. } else {
  305. }
  306. break;
  307. case PCLZIP_OPT_BY_NAME :
  308. if (($i + 1) >= $p_size) {
  309. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'");
  310. return PclZip::errorCode();
  311. }
  312. if (is_string($p_options_list[$i + 1])) {
  313. $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i + 1];
  314. } else if (is_array($p_options_list[$i + 1])) {
  315. $v_result_list[$p_options_list[$i]] = $p_options_list[$i + 1];
  316. } else {
  317. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, 'Wrong parameter value for option \'' . PclZipUtilOptionText($p_options_list[$i]) . "'");
  318. return PclZip::errorCode();
  319. }
  320. $i++;
  321. break;
  322. case PCLZIP_OPT_BY_EREG :
  323. $p_options_list[$i] = PCLZIP_OPT_BY_PREG;
  324. case PCLZIP_OPT_BY_PREG :
  325. if (($i + 1) >= $p_size) {
  326. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'");
  327. return PclZip::errorCode();
  328. }
  329. if (is_string($p_options_list[$i + 1])) {
  330. $v_result_list[$p_options_list[$i]] = $p_options_list[$i + 1];
  331. } else {
  332. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, 'Wrong parameter value for option \'' . PclZipUtilOptionText($p_options_list[$i]) . "'");
  333. return PclZip::errorCode();
  334. }
  335. $i++;
  336. break;
  337. case PCLZIP_OPT_COMMENT :
  338. case PCLZIP_OPT_ADD_COMMENT :
  339. case PCLZIP_OPT_PREPEND_COMMENT :
  340. if (($i + 1) >= $p_size) {
  341. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'");
  342. return PclZip::errorCode();
  343. }
  344. if (is_string($p_options_list[$i + 1])) {
  345. $v_result_list[$p_options_list[$i]] = $p_options_list[$i + 1];
  346. } else {
  347. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, 'Wrong parameter value for option \'' . PclZipUtilOptionText($p_options_list[$i]) . "'");
  348. return PclZip::errorCode();
  349. }
  350. $i++;
  351. break;
  352. case PCLZIP_OPT_BY_INDEX :
  353. if (($i + 1) >= $p_size) {
  354. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'");
  355. return PclZip::errorCode();
  356. }
  357. $v_work_list = array();
  358. if (is_string($p_options_list[$i + 1])) {
  359. $p_options_list[$i + 1] = strtr($p_options_list[$i + 1], ' ', '');
  360. $v_work_list = explode(",", $p_options_list[$i + 1]);
  361. } else if (is_integer($p_options_list[$i + 1])) {
  362. $v_work_list[0] = $p_options_list[$i + 1] . '-' . $p_options_list[$i + 1];
  363. } else if (is_array($p_options_list[$i + 1])) {
  364. $v_work_list = $p_options_list[$i + 1];
  365. } else {
  366. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, 'Value must be integer, string or array for option \'' . PclZipUtilOptionText($p_options_list[$i]) . "'");
  367. return PclZip::errorCode();
  368. }
  369. $v_sort_flag = false;
  370. $v_sort_value = 0;
  371. for ($j = 0; $j < sizeof($v_work_list); $j++) {
  372. $v_item_list = explode("-", $v_work_list[$j]);
  373. $v_size_item_list = sizeof($v_item_list);
  374. if ($v_size_item_list == 1) {
  375. $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
  376. $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
  377. } elseif ($v_size_item_list == 2) {
  378. $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
  379. $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
  380. } else {
  381. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, 'Too many values in index range for option \'' . PclZipUtilOptionText($p_options_list[$i]) . "'");
  382. return PclZip::errorCode();
  383. }
  384. if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
  385. $v_sort_flag = true;
  386. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, 'Invalid order of index range for option \'' . PclZipUtilOptionText($p_options_list[$i]) . "'");
  387. return PclZip::errorCode();
  388. }
  389. $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
  390. }
  391. if ($v_sort_flag) {
  392. }
  393. $i++;
  394. break;
  395. case PCLZIP_OPT_REMOVE_ALL_PATH :
  396. case PCLZIP_OPT_EXTRACT_AS_STRING :
  397. case PCLZIP_OPT_NO_COMPRESSION :
  398. case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
  399. case PCLZIP_OPT_REPLACE_NEWER :
  400. case PCLZIP_OPT_STOP_ON_ERROR :
  401. $v_result_list[$p_options_list[$i]] = true;
  402. break;
  403. case PCLZIP_OPT_SET_CHMOD :
  404. if (($i + 1) >= $p_size) {
  405. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'");
  406. return PclZip::errorCode();
  407. }
  408. $v_result_list[$p_options_list[$i]] = $p_options_list[$i + 1];
  409. $i++;
  410. break;
  411. case PCLZIP_CB_PRE_EXTRACT :
  412. case PCLZIP_CB_POST_EXTRACT :
  413. case PCLZIP_CB_PRE_ADD :
  414. case PCLZIP_CB_POST_ADD :
  415. if (($i + 1) >= $p_size) {
  416. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'");
  417. return PclZip::errorCode();
  418. }
  419. $v_function_name = $p_options_list[$i + 1];
  420. if (!function_exists($v_function_name)) {
  421. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '" . $v_function_name . "()' is not an existing function for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'");
  422. return PclZip::errorCode();
  423. }
  424. $v_result_list[$p_options_list[$i]] = $v_function_name;
  425. $i++;
  426. break;
  427. default :
  428. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 'Unknown parameter \'' . $p_options_list[$i] . "'");
  429. return PclZip::errorCode();
  430. }
  431. $i++;
  432. }
  433. if ($v_requested_options !== false) {
  434. for ($key = reset($v_requested_options); $key = key($v_requested_options); $key = next($v_requested_options)) {
  435. if ($v_requested_options[$key] == 'mandatory') {
  436. if (!isset($v_result_list[$key])) {
  437. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter " . PclZipUtilOptionText($key) . "(" . $key . ")");
  438. return PclZip::errorCode();
  439. }
  440. }
  441. }
  442. }
  443. if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
  444. }
  445. return $v_result;
  446. }
  447. function privOptionDefaultThreshold(&$p_options)
  448. {
  449. $v_result = 1;
  450. if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
  451. return $v_result;
  452. }
  453. $v_memory_limit = ini_get('memory_limit');
  454. $v_memory_limit = trim($v_memory_limit);
  455. $last = strtolower(substr($v_memory_limit, -1));
  456. if ($last == 'g') $v_memory_limit = $v_memory_limit * 1073741824;
  457. if ($last == 'm') $v_memory_limit = $v_memory_limit * 1048576;
  458. if ($last == 'k') $v_memory_limit = $v_memory_limit * 1024;
  459. $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit * PCLZIP_TEMPORARY_FILE_RATIO);
  460. if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
  461. unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
  462. }
  463. return $v_result;
  464. }
  465. function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options = false)
  466. {
  467. $v_result = 1;
  468. foreach ($p_file_list as $v_key => $v_value) {
  469. if (!isset($v_requested_options[$v_key])) {
  470. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '" . $v_key . "' for this file");
  471. return PclZip::errorCode();
  472. }
  473. switch ($v_key) {
  474. case PCLZIP_ATT_FILE_NAME :
  475. if (!is_string($v_value)) {
  476. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type " . gettype($v_value) . ". String expected for attribute '" . PclZipUtilOptionText($v_key) . "'");
  477. return PclZip::errorCode();
  478. }
  479. $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
  480. if ($p_filedescr['filename'] == '') {
  481. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '" . PclZipUtilOptionText($v_key) . "'");
  482. return PclZip::errorCode();
  483. }
  484. break;
  485. case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
  486. if (!is_string($v_value)) {
  487. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type " . gettype($v_value) . ". String expected for attribute '" . PclZipUtilOptionText($v_key) . "'");
  488. return PclZip::errorCode();
  489. }
  490. $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
  491. if ($p_filedescr['new_short_name'] == '') {
  492. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '" . PclZipUtilOptionText($v_key) . "'");
  493. return PclZip::errorCode();
  494. }
  495. break;
  496. case PCLZIP_ATT_FILE_NEW_FULL_NAME :
  497. if (!is_string($v_value)) {
  498. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type " . gettype($v_value) . ". String expected for attribute '" . PclZipUtilOptionText($v_key) . "'");
  499. return PclZip::errorCode();
  500. }
  501. $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
  502. if ($p_filedescr['new_full_name'] == '') {
  503. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '" . PclZipUtilOptionText($v_key) . "'");
  504. return PclZip::errorCode();
  505. }
  506. break;
  507. case PCLZIP_ATT_FILE_COMMENT :
  508. if (!is_string($v_value)) {
  509. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type " . gettype($v_value) . ". String expected for attribute '" . PclZipUtilOptionText($v_key) . "'");
  510. return PclZip::errorCode();
  511. }
  512. $p_filedescr['comment'] = $v_value;
  513. break;
  514. case PCLZIP_ATT_FILE_MTIME :
  515. if (!is_integer($v_value)) {
  516. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type " . gettype($v_value) . ". Integer expected for attribute '" . PclZipUtilOptionText($v_key) . "'");
  517. return PclZip::errorCode();
  518. }
  519. $p_filedescr['mtime'] = $v_value;
  520. break;
  521. case PCLZIP_ATT_FILE_CONTENT :
  522. $p_filedescr['content'] = $v_value;
  523. break;
  524. default :
  525. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 'Unknown parameter \'' . $v_key . "'");
  526. return PclZip::errorCode();
  527. }
  528. if ($v_requested_options !== false) {
  529. for ($key = reset($v_requested_options); $key = key($v_requested_options); $key = next($v_requested_options)) {
  530. if ($v_requested_options[$key] == 'mandatory') {
  531. if (!isset($p_file_list[$key])) {
  532. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter " . PclZipUtilOptionText($key) . "(" . $key . ")");
  533. return PclZip::errorCode();
  534. }
  535. }
  536. }
  537. }
  538. }
  539. return $v_result;
  540. }
  541. function privFileDescrExpand(&$p_filedescr_list, &$p_options)
  542. {
  543. $v_result = 1;
  544. $v_result_list = array();
  545. for ($i = 0; $i < sizeof($p_filedescr_list); $i++) {
  546. $v_descr = $p_filedescr_list[$i];
  547. $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false);
  548. $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
  549. if (file_exists($v_descr['filename'])) {
  550. if (@is_file($v_descr['filename'])) {
  551. $v_descr['type'] = 'file';
  552. } else if (@is_dir($v_descr['filename'])) {
  553. $v_descr['type'] = 'folder';
  554. } else if (@is_link($v_descr['filename'])) {
  555. continue;
  556. } else {
  557. continue;
  558. }
  559. } else if (isset($v_descr['content'])) {
  560. $v_descr['type'] = 'virtual_file';
  561. } else {
  562. PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, 'File \'' . $v_descr['filename'] . "' does not exist");
  563. return PclZip::errorCode();
  564. }
  565. $this->privCalculateStoredFilename($v_descr, $p_options);
  566. $v_result_list[sizeof($v_result_list)] = $v_descr;
  567. if ($v_descr['type'] == 'folder') {
  568. $v_dirlist_descr = array();
  569. $v_dirlist_nb = 0;
  570. if ($v_folder_handler = @opendir($v_descr['filename'])) {
  571. while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
  572. if (($v_item_handler == '.') || ($v_item_handler == '..')) {
  573. continue;
  574. }
  575. $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'] . '/' . $v_item_handler;
  576. if (($v_descr['stored_filename'] != $v_descr['filename']) && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
  577. if ($v_descr['stored_filename'] != '') {
  578. $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'] . '/' . $v_item_handler;
  579. } else {
  580. $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
  581. }
  582. }
  583. $v_dirlist_nb++;
  584. }
  585. @closedir($v_folder_handler);
  586. } else {
  587. }
  588. if ($v_dirlist_nb != 0) {
  589. if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
  590. return $v_result;
  591. }
  592. $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
  593. } else {
  594. }
  595. unset($v_dirlist_descr);
  596. }
  597. }
  598. $p_filedescr_list = $v_result_list;
  599. return $v_result;
  600. }
  601. function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
  602. {
  603. $v_result = 1;
  604. $v_list_detail = array();
  605. $this->privDisableMagicQuotes();
  606. if (($v_result = $this->privOpenFd('wb')) != 1) {
  607. return $v_result;
  608. }
  609. $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
  610. $this->privCloseFd();
  611. $this->privSwapBackMagicQuotes();
  612. return $v_result;
  613. }
  614. function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
  615. {
  616. $v_result = 1;
  617. $v_list_detail = array();
  618. if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) {
  619. $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
  620. return $v_result;
  621. }
  622. $this->privDisableMagicQuotes();
  623. if (($v_result = $this->privOpenFd('rb')) != 1) {
  624. $this->privSwapBackMagicQuotes();
  625. return $v_result;
  626. }
  627. $v_central_dir = array();
  628. if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
  629. $this->privCloseFd();
  630. $this->privSwapBackMagicQuotes();
  631. return $v_result;
  632. }
  633. @rewind($this->zip_fd);
  634. $v_zip_temp_name = PCLZIP_TEMPORARY_DIR . uniqid('pclzip-') . '.tmp';
  635. if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) {
  636. $this->privCloseFd();
  637. $this->privSwapBackMagicQuotes();
  638. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \'' . $v_zip_temp_name . '\' in binary write mode');
  639. return PclZip::errorCode();
  640. }
  641. $v_size = $v_central_dir['offset'];
  642. while ($v_size != 0) {
  643. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  644. $v_buffer = fread($this->zip_fd, $v_read_size);
  645. @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
  646. $v_size -= $v_read_size;
  647. }
  648. $v_swap = $this->zip_fd;
  649. $this->zip_fd = $v_zip_temp_fd;
  650. $v_zip_temp_fd = $v_swap;
  651. $v_header_list = array();
  652. if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) {
  653. fclose($v_zip_temp_fd);
  654. $this->privCloseFd();
  655. @unlink($v_zip_temp_name);
  656. $this->privSwapBackMagicQuotes();
  657. return $v_result;
  658. }
  659. $v_offset = @ftell($this->zip_fd);
  660. $v_size = $v_central_dir['size'];
  661. while ($v_size != 0) {
  662. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  663. $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
  664. @fwrite($this->zip_fd, $v_buffer, $v_read_size);
  665. $v_size -= $v_read_size;
  666. }
  667. for ($i = 0, $v_count = 0; $i < sizeof($v_header_list); $i++) {
  668. if ($v_header_list[$i]['status'] == 'ok') {
  669. if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
  670. fclose($v_zip_temp_fd);
  671. $this->privCloseFd();
  672. @unlink($v_zip_temp_name);
  673. $this->privSwapBackMagicQuotes();
  674. return $v_result;
  675. }
  676. $v_count++;
  677. }
  678. $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
  679. }
  680. $v_comment = $v_central_dir['comment'];
  681. if (isset($p_options[PCLZIP_OPT_COMMENT])) {
  682. $v_comment = $p_options[PCLZIP_OPT_COMMENT];
  683. }
  684. if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
  685. $v_comment = $v_comment . $p_options[PCLZIP_OPT_ADD_COMMENT];
  686. }
  687. if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
  688. $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT] . $v_comment;
  689. }
  690. $v_size = @ftell($this->zip_fd) - $v_offset;
  691. if (($v_result = $this->privWriteCentralHeader($v_count + $v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) {
  692. unset($v_header_list);
  693. $this->privSwapBackMagicQuotes();
  694. return $v_result;
  695. }
  696. $v_swap = $this->zip_fd;
  697. $this->zip_fd = $v_zip_temp_fd;
  698. $v_zip_temp_fd = $v_swap;
  699. $this->privCloseFd();
  700. @fclose($v_zip_temp_fd);
  701. $this->privSwapBackMagicQuotes();
  702. @unlink($this->zipname);
  703. PclZipUtilRename($v_zip_temp_name, $this->zipname);
  704. return $v_result;
  705. }
  706. function privOpenFd($p_mode)
  707. {
  708. $v_result = 1;
  709. if ($this->zip_fd != 0) {
  710. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \'' . $this->zipname . '\' already open');
  711. return PclZip::errorCode();
  712. }
  713. if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) {
  714. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \'' . $this->zipname . '\' in ' . $p_mode . ' mode');
  715. return PclZip::errorCode();
  716. }
  717. return $v_result;
  718. }
  719. function privCloseFd()
  720. {
  721. $v_result = 1;
  722. if ($this->zip_fd != 0) @fclose($this->zip_fd);
  723. $this->zip_fd = 0;
  724. return $v_result;
  725. }
  726. function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
  727. {
  728. $v_result = 1;
  729. $v_header_list = array();
  730. if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) {
  731. return $v_result;
  732. }
  733. $v_offset = @ftell($this->zip_fd);
  734. for ($i = 0, $v_count = 0; $i < sizeof($v_header_list); $i++) {
  735. if ($v_header_list[$i]['status'] == 'ok') {
  736. if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
  737. return $v_result;
  738. }
  739. $v_count++;
  740. }
  741. $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
  742. }
  743. $v_comment = '';
  744. if (isset($p_options[PCLZIP_OPT_COMMENT])) {
  745. $v_comment = $p_options[PCLZIP_OPT_COMMENT];
  746. }
  747. $v_size = @ftell($this->zip_fd) - $v_offset;
  748. if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) {
  749. unset($v_header_list);
  750. return $v_result;
  751. }
  752. return $v_result;
  753. }
  754. function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
  755. {
  756. $v_result = 1;
  757. $v_header = array();
  758. $v_nb = sizeof($p_result_list);
  759. for ($j = 0; ($j < sizeof($p_filedescr_list)) && ($v_result == 1); $j++) {
  760. $p_filedescr_list[$j]['filename'] = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
  761. if ($p_filedescr_list[$j]['filename'] == "") {
  762. continue;
  763. }
  764. if (($p_filedescr_list[$j]['type'] != 'virtual_file') && (!file_exists($p_filedescr_list[$j]['filename']))) {
  765. PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '" . $p_filedescr_list[$j]['filename'] . "' does not exist");
  766. return PclZip::errorCode();
  767. }
  768. if (($p_filedescr_list[$j]['type'] == 'file') || ($p_filedescr_list[$j]['type'] == 'virtual_file') || (($p_filedescr_list[$j]['type'] == 'folder') && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
  769. $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header, $p_options);
  770. if ($v_result != 1) {
  771. return $v_result;
  772. }
  773. $p_result_list[$v_nb++] = $v_header;
  774. }
  775. }
  776. return $v_result;
  777. }
  778. function privAddFile($p_filedescr, &$p_header, &$p_options)
  779. {
  780. $v_result = 1;
  781. $p_filename = $p_filedescr['filename'];
  782. if ($p_filename == "") {
  783. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
  784. return PclZip::errorCode();
  785. }
  786. clearstatcache();
  787. $p_header['version'] = 20;
  788. $p_header['version_extracted'] = 10;
  789. $p_header['flag'] = 0;
  790. $p_header['compression'] = 0;
  791. $p_header['crc'] = 0;
  792. $p_header['compressed_size'] = 0;
  793. $p_header['filename_len'] = strlen($p_filename);
  794. $p_header['extra_len'] = 0;
  795. $p_header['disk'] = 0;
  796. $p_header['internal'] = 0;
  797. $p_header['offset'] = 0;
  798. $p_header['filename'] = $p_filename;
  799. $p_header['stored_filename'] = $p_filedescr['stored_filename'];
  800. $p_header['extra'] = '';
  801. $p_header['status'] = 'ok';
  802. $p_header['index'] = -1;
  803. if ($p_filedescr['type'] == 'file') {
  804. $p_header['external'] = 0x00000000;
  805. $p_header['size'] = filesize($p_filename);
  806. } else if ($p_filedescr['type'] == 'folder') {
  807. $p_header['external'] = 0x00000010;
  808. $p_header['mtime'] = filemtime($p_filename);
  809. $p_header['size'] = filesize($p_filename);
  810. } else if ($p_filedescr['type'] == 'virtual_file') {
  811. $p_header['external'] = 0x00000000;
  812. $p_header['size'] = strlen($p_filedescr['content']);
  813. }
  814. if (isset($p_filedescr['mtime'])) {
  815. $p_header['mtime'] = $p_filedescr['mtime'];
  816. } else if ($p_filedescr['type'] == 'virtual_file') {
  817. $p_header['mtime'] = time();
  818. } else {
  819. $p_header['mtime'] = filemtime($p_filename);
  820. }
  821. if (isset($p_filedescr['comment'])) {
  822. $p_header['comment_len'] = strlen($p_filedescr['comment']);
  823. $p_header['comment'] = $p_filedescr['comment'];
  824. } else {
  825. $p_header['comment_len'] = 0;
  826. $p_header['comment'] = '';
  827. }
  828. if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
  829. $v_local_header = array();
  830. $this->privConvertHeader2FileInfo($p_header, $v_local_header);
  831. $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
  832. if ($v_result == 0) {
  833. $p_header['status'] = "skipped";
  834. $v_result = 1;
  835. }
  836. if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
  837. $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
  838. }
  839. }
  840. if ($p_header['stored_filename'] == "") {
  841. $p_header['status'] = "filtered";
  842. }
  843. if (strlen($p_header['stored_filename']) > 0xFF) {
  844. $p_header['status'] = 'filename_too_long';
  845. }
  846. if ($p_header['status'] == 'ok') {
  847. if ($p_filedescr['type'] == 'file') {
  848. if ((!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])))) {
  849. $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
  850. if ($v_result < PCLZIP_ERR_NO_ERROR) {
  851. return $v_result;
  852. }
  853. } else {
  854. if (($v_file = @fopen($p_filename, "rb")) == 0) {
  855. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
  856. return PclZip::errorCode();
  857. }
  858. $v_content = @fread($v_file, $p_header['size']);
  859. @fclose($v_file);
  860. $p_header['crc'] = @crc32($v_content);
  861. if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
  862. $p_header['compressed_size'] = $p_header['size'];
  863. $p_header['compression'] = 0;
  864. } else {
  865. $v_content = @gzdeflate($v_content);
  866. $p_header['compressed_size'] = strlen($v_content);
  867. $p_header['compression'] = 8;
  868. }
  869. if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
  870. @fclose($v_file);
  871. return $v_result;
  872. }
  873. @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
  874. }
  875. } else if ($p_filedescr['type'] == 'virtual_file') {
  876. $v_content = $p_filedescr['content'];
  877. $p_header['crc'] = @crc32($v_content);
  878. if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
  879. $p_header['compressed_size'] = $p_header['size'];
  880. $p_header['compression'] = 0;
  881. } else {
  882. $v_content = @gzdeflate($v_content);
  883. $p_header['compressed_size'] = strlen($v_content);
  884. $p_header['compression'] = 8;
  885. }
  886. if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
  887. @fclose($v_file);
  888. return $v_result;
  889. }
  890. @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
  891. } else if ($p_filedescr['type'] == 'folder') {
  892. if (@substr($p_header['stored_filename'], -1) != '/') {
  893. $p_header['stored_filename'] .= '/';
  894. }
  895. $p_header['size'] = 0;
  896. $p_header['external'] = 0x00000010;
  897. if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
  898. return $v_result;
  899. }
  900. }
  901. }
  902. if (isset($p_options[PCLZIP_CB_POST_ADD])) {
  903. $v_local_header = array();
  904. $this->privConvertHeader2FileInfo($p_header, $v_local_header);
  905. $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
  906. if ($v_result == 0) {
  907. $v_result = 1;
  908. }
  909. }
  910. return $v_result;
  911. }
  912. function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
  913. {
  914. $v_result = PCLZIP_ERR_NO_ERROR;
  915. $p_filename = $p_filedescr['filename'];
  916. if (($v_file = @fopen($p_filename, "rb")) == 0) {
  917. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
  918. return PclZip::errorCode();
  919. }
  920. $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR . uniqid('pclzip-') . '.gz';
  921. if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
  922. fclose($v_file);
  923. PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \'' . $v_gzip_temp_name . '\' in binary write mode');
  924. return PclZip::errorCode();
  925. }
  926. $v_size = filesize($p_filename);
  927. while ($v_size != 0) {
  928. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  929. $v_buffer = @fread($v_file, $v_read_size);
  930. @gzputs($v_file_compressed, $v_buffer, $v_read_size);
  931. $v_size -= $v_read_size;
  932. }
  933. @fclose($v_file);
  934. @gzclose($v_file_compressed);
  935. if (filesize($v_gzip_temp_name) < 18) {
  936. PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \'' . $v_gzip_temp_name . '\' has invalid filesize - should be minimum 18 bytes');
  937. return PclZip::errorCode();
  938. }
  939. if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
  940. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \'' . $v_gzip_temp_name . '\' in binary read mode');
  941. return PclZip::errorCode();
  942. }
  943. $v_binary_data = @fread($v_file_compressed, 10);
  944. $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
  945. $v_data_header['os'] = bin2hex($v_data_header['os']);
  946. @fseek($v_file_compressed, filesize($v_gzip_temp_name) - 8);
  947. $v_binary_data = @fread($v_file_compressed, 8);
  948. $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
  949. $p_header['compression'] = ord($v_data_header['cm']);
  950. $p_header['crc'] = $v_data_footer['crc'];
  951. $p_header['compressed_size'] = filesize($v_gzip_temp_name) - 18;
  952. @fclose($v_file_compressed);
  953. if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
  954. return $v_result;
  955. }
  956. if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
  957. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \'' . $v_gzip_temp_name . '\' in binary read mode');
  958. return PclZip::errorCode();
  959. }
  960. fseek($v_file_compressed, 10);
  961. $v_size = $p_header['compressed_size'];
  962. while ($v_size != 0) {
  963. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  964. $v_buffer = @fread($v_file_compressed, $v_read_size);
  965. @fwrite($this->zip_fd, $v_buffer, $v_read_size);
  966. $v_size -= $v_read_size;
  967. }
  968. @fclose($v_file_compressed);
  969. @unlink($v_gzip_temp_name);
  970. return $v_result;
  971. }
  972. function privCalculateStoredFilename(&$p_filedescr, &$p_options)
  973. {
  974. $v_result = 1;
  975. $p_filename = $p_filedescr['filename'];
  976. if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
  977. $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
  978. } else {
  979. $p_add_dir = '';
  980. }
  981. if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
  982. $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
  983. } else {
  984. $p_remove_dir = '';
  985. }
  986. if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  987. $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  988. } else {
  989. $p_remove_all_dir = 0;
  990. }
  991. if (isset($p_filedescr['new_full_name'])) {
  992. $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
  993. } else {
  994. if (isset($p_filedescr['new_short_name'])) {
  995. $v_path_info = pathinfo($p_filename);
  996. $v_dir = '';
  997. if ($v_path_info['dirname'] != '') {
  998. $v_dir = $v_path_info['dirname'] . '/';
  999. }
  1000. $v_stored_filename = $v_dir . $p_filedescr['new_short_name'];
  1001. } else {
  1002. $v_stored_filename = $p_filename;
  1003. }
  1004. if ($p_remove_all_dir) {
  1005. $v_stored_filename = basename($p_filename);
  1006. } else if ($p_remove_dir != "") {
  1007. if (substr($p_remove_dir, -1) != '/') $p_remove_dir .= "/";
  1008. if ((substr($p_filename, 0, 2) == "./") || (substr($p_remove_dir, 0, 2) == "./")) {
  1009. if ((substr($p_filename, 0, 2) == "./") && (substr($p_remove_dir, 0, 2) != "./")) {
  1010. $p_remove_dir = "./" . $p_remove_dir;
  1011. }
  1012. if ((substr($p_filename, 0, 2) != "./") && (substr($p_remove_dir, 0, 2) == "./")) {
  1013. $p_remove_dir = substr($p_remove_dir, 2);
  1014. }
  1015. }
  1016. $v_compare = PclZipUtilPathInclusion($p_remove_dir, $v_stored_filename);
  1017. if ($v_compare > 0) {
  1018. if ($v_compare == 2) {
  1019. $v_stored_filename = "";
  1020. } else {
  1021. $v_stored_filename = substr($v_stored_filename, strlen($p_remove_dir));
  1022. }
  1023. }
  1024. }
  1025. $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
  1026. if ($p_add_dir != "") {
  1027. if (substr($p_add_dir, -1) == "/") $v_stored_filename = $p_add_dir . $v_stored_filename; else $v_stored_filename = $p_add_dir . "/" . $v_stored_filename;
  1028. }
  1029. }
  1030. $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
  1031. $p_filedescr['stored_filename'] = $v_stored_filename;
  1032. return $v_result;
  1033. }
  1034. function privWriteFileHeader(&$p_header)
  1035. {
  1036. $v_result = 1;
  1037. $p_header['offset'] = ftell($this->zip_fd);
  1038. $v_date = getdate($p_header['mtime']);
  1039. $v_mtime = ($v_date['hours'] << 11) + ($v_date['minutes'] << 5) + $v_date['seconds'] / 2;
  1040. $v_mdate = (($v_date['year'] - 1980) << 9) + ($v_date['mon'] << 5) + $v_date['mday'];
  1041. $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, $p_header['version_extracted'], $p_header['flag'], $p_header['compression'], $v_mtime, $v_mdate, $p_header['crc'], $p_header['compressed_size'], $p_header['size'], strlen($p_header['stored_filename']), $p_header['extra_len']);
  1042. fputs($this->zip_fd, $v_binary_data, 30);
  1043. if (strlen($p_header['stored_filename']) != 0) {
  1044. fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
  1045. }
  1046. if ($p_header['extra_len'] != 0) {
  1047. fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
  1048. }
  1049. return $v_result;
  1050. }
  1051. function privWriteCentralFileHeader(&$p_header)
  1052. {
  1053. $v_result = 1;
  1054. $v_date = getdate($p_header['mtime']);
  1055. $v_mtime = ($v_date['hours'] << 11) + ($v_date['minutes'] << 5) + $v_date['seconds'] / 2;
  1056. $v_mdate = (($v_date['year'] - 1980) << 9) + ($v_date['mon'] << 5) + $v_date['mday'];
  1057. $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, $p_header['version'], $p_header['version_extracted'], $p_header['flag'], $p_header['compression'], $v_mtime, $v_mdate, $p_header['crc'], $p_header['compressed_size'], $p_header['size'], strlen($p_header['stored_filename']), $p_header['extra_len'], $p_header['comment_len'], $p_header['disk'], $p_header['internal'], $p_header['external'], $p_header['offset']);
  1058. fputs($this->zip_fd, $v_binary_data, 46);
  1059. if (strlen($p_header['stored_filename']) != 0) {
  1060. fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
  1061. }
  1062. if ($p_header['extra_len'] != 0) {
  1063. fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
  1064. }
  1065. if ($p_header['comment_len'] != 0) {
  1066. fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
  1067. }
  1068. return $v_result;
  1069. }
  1070. function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
  1071. {
  1072. $v_result = 1;
  1073. $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, $p_nb_entries, $p_size, $p_offset, strlen($p_comment));
  1074. fputs($this->zip_fd, $v_binary_data, 22);
  1075. if (strlen($p_comment) != 0) {
  1076. fputs($this->zip_fd, $p_comment, strlen($p_comment));
  1077. }
  1078. return $v_result;
  1079. }
  1080. function privList(&$p_list)
  1081. {
  1082. $v_result = 1;
  1083. $this->privDisableMagicQuotes();
  1084. if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) {
  1085. $this->privSwapBackMagicQuotes();
  1086. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \'' . $this->zipname . '\' in binary read mode');
  1087. return PclZip::errorCode();
  1088. }
  1089. $v_central_dir = array();
  1090. if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
  1091. $this->privSwapBackMagicQuotes();
  1092. return $v_result;
  1093. }
  1094. @rewind($this->zip_fd);
  1095. if (@fseek($this->zip_fd, $v_central_dir['offset'])) {
  1096. $this->privSwapBackMagicQuotes();
  1097. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  1098. return PclZip::errorCode();
  1099. }
  1100. for ($i = 0; $i < $v_central_dir['entries']; $i++) {
  1101. if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) {
  1102. $this->privSwapBackMagicQuotes();
  1103. return $v_result;
  1104. }
  1105. $v_header['index'] = $i;
  1106. $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
  1107. unset($v_header);
  1108. }
  1109. $this->privCloseFd();
  1110. $this->privSwapBackMagicQuotes();
  1111. return $v_result;
  1112. }
  1113. function privConvertHeader2FileInfo($p_header, &$p_info)
  1114. {
  1115. $v_result = 1;
  1116. $v_temp_path = PclZipUtilPathReduction($p_header['filename']);
  1117. $p_info['filename'] = $v_temp_path;
  1118. $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
  1119. $p_info['stored_filename'] = $v_temp_path;
  1120. $p_info['size'] = $p_header['size'];
  1121. $p_info['compressed_size'] = $p_header['compressed_size'];
  1122. $p_info['mtime'] = $p_header['mtime'];
  1123. $p_info['comment'] = $p_header['comment'];
  1124. $p_info['folder'] = (($p_header['external'] & 0x00000010) == 0x00000010);
  1125. $p_info['index'] = $p_header['index'];
  1126. $p_info['status'] = $p_header['status'];
  1127. $p_info['crc'] = $p_header['crc'];
  1128. return $v_result;
  1129. }
  1130. function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
  1131. {
  1132. $v_result = 1;
  1133. $this->privDisableMagicQuotes();
  1134. if (($p_path == "") || ((substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../") && (substr($p_path, 1, 2) != ":/"))) $p_path = "./" . $p_path;
  1135. if (($p_path != "./") && ($p_path != "/")) {
  1136. while (substr($p_path, -1) == "/") {
  1137. $p_path = substr($p_path, 0, strlen($p_path) - 1);
  1138. }
  1139. }
  1140. if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/')) {
  1141. $p_remove_path .= '/';
  1142. }
  1143. $p_remove_path_size = strlen($p_remove_path);
  1144. if (($v_result = $this->privOpenFd('rb')) != 1) {
  1145. $this->privSwapBackMagicQuotes();
  1146. return $v_result;
  1147. }
  1148. $v_central_dir = array();
  1149. if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
  1150. $this->privCloseFd();
  1151. $this->privSwapBackMagicQuotes();
  1152. return $v_result;
  1153. }
  1154. $v_pos_entry = $v_central_dir['offset'];
  1155. $j_start = 0;
  1156. for ($i = 0, $v_nb_extracted = 0; $i < $v_central_dir['entries']; $i++) {
  1157. @rewind($this->zip_fd);
  1158. if (@fseek($this->zip_fd, $v_pos_entry)) {
  1159. $this->privCloseFd();
  1160. $this->privSwapBackMagicQuotes();
  1161. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  1162. return PclZip::errorCode();
  1163. }
  1164. $v_header = array();
  1165. if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) {
  1166. $this->privCloseFd();
  1167. $this->privSwapBackMagicQuotes();
  1168. return $v_result;
  1169. }
  1170. $v_header['index'] = $i;
  1171. $v_pos_entry = ftell($this->zip_fd);
  1172. $v_extract = false;
  1173. if ((isset($p_options[PCLZIP_OPT_BY_NAME])) && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
  1174. for ($j = 0; ($j < sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
  1175. if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
  1176. if ((strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
  1177. $v_extract = true;
  1178. }
  1179. } elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
  1180. $v_extract = true;
  1181. }
  1182. }
  1183. } else if ((isset($p_options[PCLZIP_OPT_BY_PREG])) && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
  1184. if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
  1185. $v_extract = true;
  1186. }
  1187. } else if ((isset($p_options[PCLZIP_OPT_BY_INDEX])) && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
  1188. for ($j = $j_start; ($j < sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
  1189. if (($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i <= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
  1190. $v_extract = true;
  1191. }
  1192. if ($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
  1193. $j_start = $j + 1;
  1194. }
  1195. if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start'] > $i) {
  1196. break;
  1197. }
  1198. }
  1199. } else {
  1200. $v_extract = true;
  1201. }
  1202. if (($v_extract) && (($v_header['compression'] != 8) && ($v_header['compression'] != 0))) {
  1203. $v_header['status'] = 'unsupported_compression';
  1204. if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) {
  1205. $this->privSwapBackMagicQuotes();
  1206. PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, 'Filename \'' . $v_header['stored_filename'] . "' is " . "compressed by an unsupported compression " . "method (" . $v_header['compression'] . ") ");
  1207. return PclZip::errorCode();
  1208. }
  1209. }
  1210. if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
  1211. $v_header['status'] = 'unsupported_encryption';
  1212. if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) {
  1213. $this->privSwapBackMagicQuotes();
  1214. PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'Unsupported encryption for ' . ' filename \'' . $v_header['stored_filename'] . "'");
  1215. return PclZip::errorCode();
  1216. }
  1217. }
  1218. if (($v_extract) && ($v_header['status'] != 'ok')) {
  1219. $v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++]);
  1220. if ($v_result != 1) {
  1221. $this->privCloseFd();
  1222. $this->privSwapBackMagicQuotes();
  1223. return $v_result;
  1224. }
  1225. $v_extract = false;
  1226. }
  1227. if ($v_extract) {
  1228. @rewind($this->zip_fd);
  1229. if (@fseek($this->zip_fd, $v_header['offset'])) {
  1230. $this->privCloseFd();
  1231. $this->privSwapBackMagicQuotes();
  1232. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  1233. return PclZip::errorCode();
  1234. }
  1235. if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
  1236. $v_string = '';
  1237. $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
  1238. if ($v_result1 < 1) {
  1239. $this->privCloseFd();
  1240. $this->privSwapBackMagicQuotes();
  1241. return $v_result1;
  1242. }
  1243. if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1) {
  1244. $this->privCloseFd();
  1245. $this->privSwapBackMagicQuotes();
  1246. return $v_result;
  1247. }
  1248. $p_file_list[$v_nb_extracted]['content'] = $v_string;
  1249. $v_nb_extracted++;
  1250. if ($v_result1 == 2) {
  1251. break;
  1252. }
  1253. } elseif ((isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
  1254. $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
  1255. if ($v_result1 < 1) {
  1256. $this->privCloseFd();
  1257. $this->privSwapBackMagicQuotes();
  1258. return $v_result1;
  1259. }
  1260. if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
  1261. $this->privCloseFd();
  1262. $this->privSwapBackMagicQuotes();
  1263. return $v_result;
  1264. }
  1265. if ($v_result1 == 2) {
  1266. break;
  1267. }
  1268. } else {
  1269. $v_result1 = $this->privExtractFile($v_header, $p_path, $p_remove_path, $p_remove_all_path, $p_options);
  1270. if ($v_result1 < 1) {
  1271. $this->privCloseFd();
  1272. $this->privSwapBackMagicQuotes();
  1273. return $v_result1;
  1274. }
  1275. if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
  1276. $this->privCloseFd();
  1277. $this->privSwapBackMagicQuotes();
  1278. return $v_result;
  1279. }
  1280. if ($v_result1 == 2) {
  1281. break;
  1282. }
  1283. }
  1284. }
  1285. }
  1286. $this->privCloseFd();
  1287. $this->privSwapBackMagicQuotes();
  1288. return $v_result;
  1289. }
  1290. function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
  1291. {
  1292. $v_result = 1;
  1293. if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
  1294. return $v_result;
  1295. }
  1296. if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
  1297. }
  1298. function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter = true)
  1299. {
  1300. if (stristr(php_uname(), 'windows')) {
  1301. if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
  1302. $p_path = substr($p_path, $v_position + 1);
  1303. }
  1304. if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0, 1) == '\\')) {
  1305. $p_path = strtr($p_path, '\\', '/');
  1306. }
  1307. }
  1308. return $p_path;
  1309. }