简体   繁体   中英

Preserving file info while creating tar in PHP

In PHP, I created tar file using Phar object but it does not save the file info like the modified time, permissions etc.

Is there any way to save such info in the tar file created?

I tried buildFromDirectory(), addFile(), nothing works.

The phar file format does actually contain "meta data" for files - see the description at http://php.net/manual/en/phar.fileformat.manifestfile.php

By default, no meta data are stored on the files. You can check that with the phar tool provided in the PHP release zips:

$ phar meta-get -f phorkie-0.5.0.phar -e www/www-security.php
No Metadata

But since you asked how you can add them: with meta-set :

$ php -dphar.readonly=0 `which phar` meta-set -f phorkie-0.5.0.phar\
      -e www/www-security.php -m 's:8:"hi there";'
$ phar meta-get -f phorkie-0.5.0.phar -e www/www-security.php
s:8:"hi there";

Programmatically, you can use PharFileInfo::setMetadata() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM