Friday, 27 September 2019

ZipArchive ignores date_default_timezone_set for files placed in the .zip file

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.

Thanks a lot!



from ZipArchive ignores date_default_timezone_set for files placed in the .zip file

No comments:

Post a Comment