pear - Adding files to a Tar Archive in PHP with different filenames -


i'm using archive-tar pear extension php add collection of files tar archive.

these files stored on filer extension e.g.

 filename.tgz.104850209.t or filename2.doc.2154395.t 

i'd remove extension while adding files tar archive have files: filename.tgz , filename2.doc

is there way of doing without having copy/rename source files first before adding archive?

thanks, mark.

archive_tar in latest version not yet support such functionality out of box. part of functionality in _addfile() , other part in _addstring().

most easy extend archive_tar , proxy calls _writeheaderblock() public, applying map on filename parameter rename when written headers.

class patched_archive_tar extends archive_tar {     var $renamemap = array();      function _writeheaderblock($p_filename, $p_size, $p_mtime=0, $p_perms=0,                                $p_type='', $p_uid=0, $p_gid=0)     {         return parent::_writeheaderblock($this->_translatefilename($p_filename),                                    $p_size, $p_mtime=0, $p_perms=0,                                   $p_type='', $p_uid=0, $p_gid=0);     }      function _translatefilename($orignal)     {         $map = $this->renamemap;         if (isset($map[$orignal])) {             return $map[$orignal];         }          return $original;     } } 

usage:

$obj = new patched_archive_tar('dummy.tar'); // name of archive  $files = array('mystuff/ad.gif',                 'mystuff/alcon.doc.t',                 'mystuff/alcon.xls.t');   // files store in archive  $obj->renamemap = array(     'mystuff/alcon.doc.t' => 'mystuff/alcon.doc',     'mystuff/alcon.xls.t' => 'mystuff/alcon.xls', )  // files rename  if ($obj->create($files)) {     echo 'created successfully!'; } else {     echo 'error in file creation'; } 

this quick , dirty worky. better see function noticed @ beginning _addfile() , _addstring(), want 1 able add file (as _addfile()) specifiying filename (as _addstring()).


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -