#StackBounty: #php #zip #ziparchive ZipArchive ignores date_default_timezone_set for files placed in the .zip file

Bounty: 50

I’m running PHP 7.0.33 on a Linux server (shared web hosting).

With date_default_timezone_set('Europe/Rome'); I can properly set my timezone.

echo date('Y-m-d H:i:s'); shows the correct date-time.

But the files added in a .zip with ZipArchive obtain the server date-time.

Here is the code I use to zip the files:

$zip = new ZipArchive;
$zip->open($pathZip, ZipArchive::CREATE);
foreach($fileList as $fileName => $fileContents)
{
    $zip->addFromString($fileName, $fileContents);
}
$zip->close();
// Note: I removed all try-catch and false returns checks to simplify the code

How to add files in the .zip maintaining the timezone set with date_default_timezone_set, possibly using ZipArchive?

I already read this post on SO, but it’s quite old.


Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.