b2evolution PHP Cross Reference Blogging Systems

Source: /inc/_ext/_zip_archives.php - 712 lines - 20253 bytes - Summary - Text - Print

Description: TAR/GZIP/BZIP2/ZIP ARCHIVE CLASSES 2.1 By Devin Doucette Copyright (c) 2005 Devin Doucette Email bugs/suggestions to darksnoopy@shaw.ca

   1  <?php
   2  /**
   3   * TAR/GZIP/BZIP2/ZIP ARCHIVE CLASSES 2.1
   4   * By Devin Doucette
   5   * Copyright (c) 2005 Devin Doucette
   6   * Email bugs/suggestions to darksnoopy@shaw.ca
   7   * @link http://www.phpclasses.org/browse/package/945.html
   8   *
   9   * This script has been created and released under
  10   * the GNU GPL and is free to use and redistribute
  11   * only if this copyright statement is not removed
  12   *
  13   * b2evolution - {@link http://b2evolution.net/}
  14   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  15   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
  16   *
  17   * @author Devin Doucette - darksnoopy@shaw.ca
  18   *
  19   * @package evocore
  20   */
  21  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  22  
  23  /**
  24   * Class Archive
  25   *
  26   * @author Devin Doucette
  27   * @package evocore
  28   */
  29  class archive
  30  {
  31  	function archive($name)
  32      {
  33          $this->options = array (
  34              'basedir' => ".",
  35              'name' => $name,
  36              'prepend' => "",
  37              'inmemory' => 0,
  38              'overwrite' => 0,
  39              'recurse' => 1,
  40              'storepaths' => 1,
  41              'followlinks' => 0,
  42              'level' => 3,
  43              'method' => 1,
  44              'sfx' => "",
  45              'type' => "",
  46              'comment' => ""
  47          );
  48          $this->files = array ();
  49          $this->exclude = array ();
  50          $this->storeonly = array ();
  51          $this->error = array ();
  52      }
  53  
  54  	function set_options($options)
  55      {
  56          foreach ($options as $key => $value)
  57              $this->options[$key] = $value;
  58          if (!empty ($this->options['basedir']))
  59          {
  60              $this->options['basedir'] = str_replace("\\", "/", $this->options['basedir']);
  61              $this->options['basedir'] = preg_replace("/\/+/", "/", $this->options['basedir']);
  62              $this->options['basedir'] = preg_replace("/\/$/", "", $this->options['basedir']);
  63          }
  64          if (!empty ($this->options['name']))
  65          {
  66              $this->options['name'] = str_replace("\\", "/", $this->options['name']);
  67              $this->options['name'] = preg_replace("/\/+/", "/", $this->options['name']);
  68          }
  69          if (!empty ($this->options['prepend']))
  70          {
  71              $this->options['prepend'] = str_replace("\\", "/", $this->options['prepend']);
  72              $this->options['prepend'] = preg_replace("/^(\.*\/+)+/", "", $this->options['prepend']);
  73              $this->options['prepend'] = preg_replace("/\/+/", "/", $this->options['prepend']);
  74              $this->options['prepend'] = preg_replace("/\/$/", "", $this->options['prepend']) . "/";
  75          }
  76      }
  77  
  78  	function create_archive()
  79      {
  80          $this->make_list();
  81  
  82          if ($this->options['inmemory'] == 0)
  83          {
  84              $pwd = getcwd();
  85              chdir($this->options['basedir']);
  86              if ($this->options['overwrite'] == 0 && file_exists($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : "")))
  87              {
  88                  $this->error[] = "File {$this->options['name']} already exists.";
  89                  chdir($pwd);
  90                  return 0;
  91              }
  92              else if ($this->archive = @fopen($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : ""), "wb+"))
  93                  chdir($pwd);
  94              else
  95              {
  96                  $this->error[] = "Could not open {$this->options['name']} for writing.";
  97                  chdir($pwd);
  98                  return 0;
  99              }
 100          }
 101          else
 102              $this->archive = "";
 103  
 104          switch ($this->options['type'])
 105          {
 106          case "zip":
 107              if (!$this->create_zip())
 108              {
 109                  $this->error[] = "Could not create zip file.";
 110                  return 0;
 111              }
 112              break;
 113          case "bzip":
 114              if (!$this->create_tar())
 115              {
 116                  $this->error[] = "Could not create tar file.";
 117                  return 0;
 118              }
 119              if (!$this->create_bzip())
 120              {
 121                  $this->error[] = "Could not create bzip2 file.";
 122                  return 0;
 123              }
 124              break;
 125          case "gzip":
 126              if (!$this->create_tar())
 127              {
 128                  $this->error[] = "Could not create tar file.";
 129                  return 0;
 130              }
 131              if (!$this->create_gzip())
 132              {
 133                  $this->error[] = "Could not create gzip file.";
 134                  return 0;
 135              }
 136              break;
 137          case "tar":
 138              if (!$this->create_tar())
 139              {
 140                  $this->error[] = "Could not create tar file.";
 141                  return 0;
 142              }
 143          }
 144  
 145          if ($this->options['inmemory'] == 0)
 146          {
 147              fclose($this->archive);
 148              if ($this->options['type'] == "gzip" || $this->options['type'] == "bzip")
 149                  unlink($this->options['basedir'] . "/" . $this->options['name'] . ".tmp");
 150          }
 151      }
 152  
 153  	function add_data($data)
 154      {
 155          if ($this->options['inmemory'] == 0)
 156              fwrite($this->archive, $data);
 157          else
 158              $this->archive .= $data;
 159      }
 160  
 161  	function make_list()
 162      {
 163          if (!empty ($this->exclude))
 164              foreach ($this->files as $key => $value)
 165                  foreach ($this->exclude as $current)
 166                      if ($value['name'] == $current['name'])
 167                          unset ($this->files[$key]);
 168          if (!empty ($this->storeonly))
 169              foreach ($this->files as $key => $value)
 170                  foreach ($this->storeonly as $current)
 171                      if ($value['name'] == $current['name'])
 172                          $this->files[$key]['method'] = 0;
 173          unset ($this->exclude, $this->storeonly);
 174      }
 175  
 176  	function add_files( $list, $exclude = array() )
 177      {
 178          $temp = $this->list_files( $list, $exclude );
 179          foreach ($temp as $current)
 180              $this->files[] = $current;
 181      }
 182  
 183  	function exclude_files($list)
 184      {
 185          $temp = $this->list_files($list);
 186          foreach ($temp as $current)
 187              $this->exclude[] = $current;
 188      }
 189  
 190  	function store_files($list)
 191      {
 192          $temp = $this->list_files($list);
 193          foreach ($temp as $current)
 194              $this->storeonly[] = $current;
 195      }
 196  
 197  	function list_files( $list, $exclude = array() )
 198      {
 199          if (!is_array ($list))
 200          {
 201              $temp = $list;
 202              $list = array ($temp);
 203              unset ($temp);
 204          }
 205  
 206          $files = array ();
 207  
 208          $pwd = getcwd();
 209          chdir($this->options['basedir']);
 210  
 211          foreach ($list as $current)
 212          {
 213              $current = str_replace("\\", "/", $current);
 214              $current = preg_replace("/\/+/", "/", $current);
 215              $current = preg_replace("/\/$/", "", $current);
 216              if (strstr($current, "*"))
 217              {
 218                  $regex = preg_replace("/([\\\^\$\.\[\]\|\(\)\?\+\{\}\/])/", "\\\\\\1", $current);
 219                  $regex = str_replace("*", ".*", $regex);
 220                  $dir = strstr($current, "/") ? substr($current, 0, strrpos($current, "/")) : ".";
 221                  $temp = $this->parse_dir( $dir, $exclude );
 222                  foreach ($temp as $current2)
 223                      if (preg_match("/^{$regex}$/i", $current2['name']))
 224                          $files[] = $current2;
 225                  unset ($regex, $dir, $temp, $current);
 226              }
 227              else if (@is_dir($current))
 228              {
 229                  $temp = $this->parse_dir( $current, $exclude );
 230                  foreach ($temp as $file)
 231                      $files[] = $file;
 232                  unset ($temp, $file);
 233              }
 234              else if (@file_exists($current))
 235                  $files[] = array ('name' => $current, 'name2' => $this->options['prepend'] .
 236                      preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($current, "/")) ?
 237                      substr($current, strrpos($current, "/") + 1) : $current),
 238                      'type' => @is_link($current) && $this->options['followlinks'] == 0 ? 2 : 0,
 239                      'ext' => substr($current, strrpos($current, ".")), 'stat' => stat($current));
 240          }
 241  
 242          chdir($pwd);
 243  
 244          unset ($current, $pwd);
 245  
 246          usort($files, array ("archive", "sort_files"));
 247  
 248          return $files;
 249      }
 250  
 251  	function parse_dir( $dirname, $exclude = array() )
 252      {
 253          if ($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/", $dirname))
 254              $files = array (array ('name' => $dirname, 'name2' => $this->options['prepend'] .
 255                  preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($dirname, "/")) ?
 256                  substr($dirname, strrpos($dirname, "/") + 1) : $dirname), 'type' => 5, 'stat' => stat($dirname)));
 257          else
 258              $files = array ();
 259          $dir = @opendir($dirname);
 260  
 261          while ($file = @readdir($dir))
 262          {
 263              if( in_array( $file, $exclude ) )
 264              { // Skip this file/folder
 265                  continue;
 266              }
 267              $fullname = $dirname . "/" . $file;
 268              if ($file == "." || $file == "..")
 269                  continue;
 270              else if (@is_dir($fullname))
 271              {
 272                  if (empty ($this->options['recurse']))
 273                      continue;
 274                  $temp = $this->parse_dir( $fullname, $exclude );
 275                  foreach ($temp as $file2)
 276                      $files[] = $file2;
 277              }
 278              else if (@file_exists($fullname))
 279                  $files[] = array ('name' => $fullname, 'name2' => $this->options['prepend'] .
 280                      preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($fullname, "/")) ?
 281                      substr($fullname, strrpos($fullname, "/") + 1) : $fullname),
 282                      'type' => @is_link($fullname) && $this->options['followlinks'] == 0 ? 2 : 0,
 283                      'ext' => substr($file, strrpos($file, ".")), 'stat' => stat($fullname));
 284          }
 285  
 286          @closedir($dir);
 287  
 288          return $files;
 289      }
 290  
 291      function sort_files($a, $b)
 292      {
 293          if ($a['type'] != $b['type'])
 294              if ($a['type'] == 5 || $b['type'] == 2)
 295                  return -1;
 296              else if ($a['type'] == 2 || $b['type'] == 5)
 297                  return 1;
 298          else if ($a['type'] == 5)
 299              return strcmp(strtolower($a['name']), strtolower($b['name']));
 300          else if ($a['ext'] != $b['ext'])
 301              return strcmp($a['ext'], $b['ext']);
 302          else if ($a['stat'][7] != $b['stat'][7])
 303              return $a['stat'][7] > $b['stat'][7] ? -1 : 1;
 304          else
 305              return strcmp(strtolower($a['name']), strtolower($b['name']));
 306          return 0;
 307      }
 308  
 309      function download_file()
 310      {
 311          if ($this->options['inmemory'] == 0)
 312          {
 313              $this->error[] = "Can only use download_file() if archive is in memory. Redirect to file otherwise, it is faster.";
 314              return;
 315          }
 316          switch ($this->options['type'])
 317          {
 318          case "zip":
 319              header("Content-Type: application/zip");
 320              break;
 321          case "bzip":
 322              header("Content-Type: application/x-bzip2");
 323              break;
 324          case "gzip":
 325              header("Content-Type: application/x-gzip");
 326              break;
 327          case "tar":
 328              header("Content-Type: application/x-tar");
 329          }
 330          $header = "Content-Disposition: attachment; filename=\"";
 331          $header .= strstr($this->options['name'], "/") ? substr($this->options['name'], strrpos($this->options['name'], "/") + 1) : $this->options['name'];
 332          $header .= "\"";
 333          header($header);
 334          header("Content-Length: " . strlen($this->archive));
 335          header("Content-Transfer-Encoding: binary");
 336          header("Cache-Control: no-cache, must-revalidate, max-age=60");
 337          header("Expires: Sat, 01 Jan 2000 12:00:00 GMT");
 338          print($this->archive);
 339      }
 340  }
 341  
 342  /**
 343   * Class Tar file
 344   *
 345   * @author Devin Doucette
 346   * @package evocore
 347   */
 348  class tar_file extends archive
 349  {
 350  	function tar_file($name)
 351      {
 352          $this->archive($name);
 353          $this->options['type'] = "tar";
 354      }
 355  
 356  	function create_tar()
 357      {
 358          $pwd = getcwd();
 359          chdir($this->options['basedir']);
 360  
 361          foreach ($this->files as $current)
 362          {
 363              if ($current['name'] == $this->options['name'])
 364                  continue;
 365              if (strlen($current['name2']) > 99)
 366              {
 367                  $path = substr($current['name2'], 0, strpos($current['name2'], "/", strlen($current['name2']) - 100) + 1);
 368                  $current['name2'] = substr($current['name2'], strlen($path));
 369                  if (strlen($path) > 154 || strlen($current['name2']) > 99)
 370                  {
 371                      $this->error[] = "Could not add {$path}{$current['name2']} to archive because the filename is too long.";
 372                      continue;
 373                  }
 374              }
 375              $block = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12", $current['name2'], sprintf("%07o",
 376                  $current['stat'][2]), sprintf("%07o", $current['stat'][4]), sprintf("%07o", $current['stat'][5]),
 377                  sprintf("%011o", $current['type'] == 2 ? 0 : $current['stat'][7]), sprintf("%011o", $current['stat'][9]),
 378                  "        ", $current['type'], $current['type'] == 2 ? @readlink($current['name']) : "", "ustar ", " ",
 379                  "Unknown", "Unknown", "", "", !empty ($path) ? $path : "", "");
 380  
 381              $checksum = 0;
 382              for ($i = 0; $i < 512; $i++)
 383                  $checksum += ord(substr($block, $i, 1));
 384              $checksum = pack("a8", sprintf("%07o", $checksum));
 385              $block = substr_replace($block, $checksum, 148, 8);
 386  
 387              if ($current['type'] == 2 || $current['stat'][7] == 0)
 388                  $this->add_data($block);
 389              else if ($fp = @fopen($current['name'], "rb"))
 390              {
 391                  $this->add_data($block);
 392                  while ($temp = fread($fp, 1048576))
 393                      $this->add_data($temp);
 394                  if ($current['stat'][7] % 512 > 0)
 395                  {
 396                      $temp = "";
 397                      for ($i = 0; $i < 512 - $current['stat'][7] % 512; $i++)
 398                          $temp .= "\0";
 399                      $this->add_data($temp);
 400                  }
 401                  fclose($fp);
 402              }
 403              else
 404                  $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
 405          }
 406  
 407          $this->add_data(pack("a1024", ""));
 408  
 409          chdir($pwd);
 410  
 411          return 1;
 412      }
 413  
 414  	function extract_files()
 415      {
 416          $pwd = getcwd();
 417          chdir($this->options['basedir']);
 418  
 419          if ($fp = $this->open_archive())
 420          {
 421              if ($this->options['inmemory'] == 1)
 422                  $this->files = array ();
 423  
 424              while ($block = fread($fp, 512))
 425              {
 426                  $temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp", $block);
 427                  $file = array (
 428                      'name' => $temp['prefix'] . $temp['name'],
 429                      'stat' => array (
 430                          2 => $temp['mode'],
 431                          4 => octdec($temp['uid']),
 432                          5 => octdec($temp['gid']),
 433                          7 => octdec($temp['size']),
 434                          9 => octdec($temp['mtime']),
 435                      ),
 436                      'checksum' => octdec($temp['checksum']),
 437                      'type' => $temp['type'],
 438                      'magic' => $temp['magic'],
 439                  );
 440                  if ($file['checksum'] == 0x00000000)
 441                      break;
 442                  else if (substr($file['magic'], 0, 5) != "ustar")
 443                  {
 444                      $this->error[] = "This script does not support extracting this type of tar file.";
 445                      break;
 446                  }
 447                  $block = substr_replace($block, "        ", 148, 8);
 448                  $checksum = 0;
 449                  for ($i = 0; $i < 512; $i++)
 450                      $checksum += ord(substr($block, $i, 1));
 451                  if ($file['checksum'] != $checksum)
 452                      $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
 453  
 454                  if ($this->options['inmemory'] == 1)
 455                  {
 456                      $file['data'] = fread($fp, $file['stat'][7]);
 457                      fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
 458                      unset ($file['checksum'], $file['magic']);
 459                      $this->files[] = $file;
 460                  }
 461                  else if ($file['type'] == 5)
 462                  {
 463                      evo_mkdir($file['name'], $file['stat'][2]);
 464                  }
 465                  else if ($this->options['overwrite'] == 0 && file_exists($file['name']))
 466                  {
 467                      $this->error[] = "{$file['name']} already exists.";
 468                      continue;
 469                  }
 470                  else if ($file['type'] == 2)
 471                  {
 472                      symlink($temp['symlink'], $file['name']);
 473                      chmod($file['name'], $file['stat'][2]);
 474                  }
 475                  else if ($new = @fopen($file['name'], "wb"))
 476                  {
 477                      fwrite($new, fread($fp, $file['stat'][7]));
 478                      fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
 479                      fclose($new);
 480                      chmod($file['name'], $file['stat'][2]);
 481                  }
 482                  else
 483                  {
 484                      $this->error[] = "Could not open {$file['name']} for writing.";
 485                      continue;
 486                  }
 487                  chown($file['name'], $file['stat'][4]);
 488                  chgrp($file['name'], $file['stat'][5]);
 489                  touch($file['name'], $file['stat'][9]);
 490                  unset ($file);
 491              }
 492          }
 493          else
 494              $this->error[] = "Could not open file {$this->options['name']}";
 495  
 496          chdir($pwd);
 497      }
 498  
 499  	function open_archive()
 500      {
 501          return @fopen($this->options['name'], "rb");
 502      }
 503  }
 504  
 505  /**
 506   * Class Gzip_file
 507   *
 508   * @author Devin Doucette
 509   * @package evocore
 510   */
 511  class gzip_file extends tar_file
 512  {
 513  	function gzip_file($name)
 514      {
 515          $this->tar_file($name);
 516          $this->options['type'] = "gzip";
 517      }
 518  
 519  	function create_gzip()
 520      {
 521          if ($this->options['inmemory'] == 0)
 522          {
 523              $pwd = getcwd();
 524              chdir($this->options['basedir']);
 525              if ($fp = gzopen($this->options['name'], "wb{$this->options['level']}"))
 526              {
 527                  fseek($this->archive, 0);
 528                  while ($temp = fread($this->archive, 1048576))
 529                      gzwrite($fp, $temp);
 530                  gzclose($fp);
 531                  chdir($pwd);
 532              }
 533              else
 534              {
 535                  $this->error[] = "Could not open {$this->options['name']} for writing.";
 536                  chdir($pwd);
 537                  return 0;
 538              }
 539          }
 540          else
 541              $this->archive = gzencode($this->archive, $this->options['level']);
 542  
 543          return 1;
 544      }
 545  
 546  	function open_archive()
 547      {
 548          return @gzopen($this->options['name'], "rb");
 549      }
 550  }
 551  
 552  /**
 553   * Class Bzip_file
 554   *
 555   * @author Devin Doucette
 556   * @package evocore
 557   */
 558  class bzip_file extends tar_file
 559  {
 560  	function bzip_file($name)
 561      {
 562          $this->tar_file($name);
 563          $this->options['type'] = "bzip";
 564      }
 565  
 566  	function create_bzip()
 567      {
 568          if ($this->options['inmemory'] == 0)
 569          {
 570              $pwd = getcwd();
 571              chdir($this->options['basedir']);
 572              if ($fp = bzopen($this->options['name'], "wb"))
 573              {
 574                  fseek($this->archive, 0);
 575                  while ($temp = fread($this->archive, 1048576))
 576                      bzwrite($fp, $temp);
 577                  bzclose($fp);
 578                  chdir($pwd);
 579              }
 580              else
 581              {
 582                  $this->error[] = "Could not open {$this->options['name']} for writing.";
 583                  chdir($pwd);
 584                  return 0;
 585              }
 586          }
 587          else
 588              $this->archive = bzcompress($this->archive, $this->options['level']);
 589  
 590          return 1;
 591      }
 592  
 593  	function open_archive()
 594      {
 595          return @bzopen($this->options['name'], "r");
 596      }
 597  }
 598  
 599  /**
 600   * Class Zip_file
 601   *
 602   * @author Devin Doucette
 603   * @package evocore
 604   */
 605  class zip_file extends archive
 606  {
 607  	function zip_file($name)
 608      {
 609          $this->archive($name);
 610          $this->options['type'] = "zip";
 611      }
 612  
 613  	function create_zip()
 614      {
 615          $files = 0;
 616          $offset = 0;
 617          $central = "";
 618  
 619          if (!empty ($this->options['sfx']))
 620              if ($fp = @fopen($this->options['sfx'], "rb"))
 621              {
 622                  $temp = fread($fp, filesize($this->options['sfx']));
 623                  fclose($fp);
 624                  $this->add_data($temp);
 625                  $offset += strlen($temp);
 626                  unset ($temp);
 627              }
 628              else
 629                  $this->error[] = "Could not open sfx module from {$this->options['sfx']}.";
 630  
 631          $pwd = getcwd();
 632          chdir($this->options['basedir']);
 633  
 634          foreach ($this->files as $current)
 635          {
 636              if ($current['name'] == $this->options['name'])
 637                  continue;
 638  
 639              $timedate = explode(" ", date("Y n j G i s", $current['stat'][9]));
 640              $timedate = ($timedate[0] - 1980 << 25) | ($timedate[1] << 21) | ($timedate[2] << 16) |
 641                  ($timedate[3] << 11) | ($timedate[4] << 5) | ($timedate[5]);
 642  
 643              $block = pack("VvvvV", 0x04034b50, 0x000A, 0x0000, (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate);
 644  
 645              if ( ( $current['stat'][7] == 0 || @is_dir( $current['name'] ) )&& $current['type'] == 5 )
 646              {
 647                  $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000);
 648                  $block .= $current['name2'] . "/";
 649                  $this->add_data($block);
 650                  $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
 651                      (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
 652                      0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
 653                  $central .= $current['name2'] . "/";
 654                  $files++;
 655                  $offset += (31 + strlen($current['name2']));
 656              }
 657              else if ($current['stat'][7] == 0)
 658              {
 659                  $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000);
 660                  $block .= $current['name2'];
 661                  $this->add_data($block);
 662                  $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
 663                      (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
 664                      0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
 665                  $central .= $current['name2'];
 666                  $files++;
 667                  $offset += (30 + strlen($current['name2']));
 668              }
 669              else if ($fp = @fopen($current['name'], "rb"))
 670              {
 671                  $temp = fread($fp, $current['stat'][7]);
 672                  fclose($fp);
 673                  $crc32 = crc32($temp);
 674                  if (!isset($current['method']) && $this->options['method'] == 1)
 675                  {
 676                      $temp = gzcompress($temp, $this->options['level']);
 677                      $size = strlen($temp) - 6;
 678                      $temp = substr($temp, 2, $size);
 679                  }
 680                  else
 681                      $size = strlen($temp);
 682                  $block .= pack("VVVvv", $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000);
 683                  $block .= $current['name2'];
 684                  $this->add_data($block);
 685                  $this->add_data($temp);
 686                  unset ($temp);
 687                  $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
 688                      (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
 689                      $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, 0x00000000, $offset);
 690                  $central .= $current['name2'];
 691                  $files++;
 692                  $offset += (30 + strlen($current['name2']) + $size);
 693              }
 694              else
 695                  $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
 696          }
 697  
 698          $this->add_data($central);
 699  
 700          $this->add_data(pack("VvvvvVVv", 0x06054b50, 0x0000, 0x0000, $files, $files, strlen($central), $offset,
 701              !empty ($this->options['comment']) ? strlen($this->options['comment']) : 0x0000));
 702  
 703          if (!empty ($this->options['comment']))
 704              $this->add_data($this->options['comment']);
 705  
 706          chdir($pwd);
 707  
 708          return 1;
 709      }
 710  }
 711  
 712  ?>

title

Description

title

Description

title

Description

title

title

Body