php - creating archive with pear Archive_Tar -


i'm creating tar archive following function

public static function packdirectory($path, $outpath) {     require_once 'archive/tar.php';      $obj = new archive_tar($outpath);     $obj->seterrorhandling(pear_error_print);      $handle=opendir($path);     $files = array();      while (false !== ($file = readdir($handle))) {         if ($file == '.' || $file == '..') {             continue;         }          $files[] = $path . '/' . $file;     }      $obj->create($files); } 

path folder1/folder2/folder3/. creates archive following

folder1/folder2/folder3/filea folder1/folder2/folder3/fileb folder1/folder2/folder3/filec folder1/folder2/folder3/subfolder/filed 

i want be

filea fileb filec subfolder/filed 

how tha can done?

you need use createmodify method - takes 2 more parameters archive_tar's create method. complete, these 3 parameters are:

  • $p_filelist - array of filenames
  • $p_add_dir - string/path prepended filenames.
  • $p_remove_dir - string/path removed filenames.

i changed packdirectory method slightly, include third parameter of remove filenames. looks this:

<?php class packer {      public static function packdirectory($path, $outpath, $strippath = '') {         require_once 'archive/tar.php';          $obj = new archive_tar($outpath);         $obj->seterrorhandling(pear_error_print);          $handle=opendir($path);         $files = array();          while (false !== ($file = readdir($handle))) {             if ($file == '.' || $file == '..') {                 continue;             }              $files[] = $path . '/' . $file;         }          if ($strippath === '') {             $obj->create($files);         } else {             $obj->createmodify($files, '', $strippath);         }     } }  packer::packdirectory(     "folder1/folder2/folder3",      "packer.tar",      'folder1/folder2/folder3' ); ?> 

Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -