问题
Is it possible to use the ZipArchive class in PHP to change the created date or modified date of a file inside of a zip file without writing the file to a disk and using touch on it and then adding the file to the zip again
回答1:
No, this is not possible. The external attributes have nothing to do with the file modified time, which is stored before the external attributes. I've looked at all the compression libraries in PHP, and this is not possible. I would recommend using JSON instead, if your purpose is to simply pack the data into one file and ease-of-use isn't as much of a concern as preservation of the file attributes.
I'm not sure if any software supports setting the file modified time, so you would have to alter the source code to support such a thing or code it yourself. I had a look at the bzip source code (NOT the PHP extension), and it simply copies this from the source file. Furthermore, the default file modified time is stored in DOS format, which is only accurate to the nearest 2 seconds, so you would have to store the proper file modified time in an extra field. PHP does not support writing to or reading extra fields.
The simplest solution would be using your filesystem.
Sources:
Wikipedia article: https://en.wikipedia.org/wiki/Zip_%28file_format%29
Basic description: http://www.forensicswiki.org/wiki/ZIP
Reverse engineering: http://www.sweetscape.com/010editor/templates/files/ZIPTemplate.bt
Bzip: http://www.bzip.org/
PHP comment: http://php.net/manual/en/ziparchive.statindex.php#118629
来源:https://stackoverflow.com/questions/26365627/change-the-created-date-attribute-on-a-file-in-a-zip-archive-using-php