PHP - 解压缩文件的修改时间设置为服务器的时区 - 如何更改?



所以我们的代码创建了一个zip文件,里面是来自特定文件夹的PDF。一切正常,除了当此zip文件下载到计算机并提取文件时 - 每个PDF文件的修改时间遵循服务器的时区。(我们的网站位于 GoDaddy 共享服务器上,位于亚利桑那州。我们位于新加坡。

有没有办法修改它?我尝试设置默认时区或使用 touch((,但没有运气。

// Initialize archive object
$zip = new ZipArchive();
$res = $zip->open(plugin_dir_path( __FILE__ ).'MortgageWise-All-Reports.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
if ($res === TRUE) {
// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath)
);
foreach ($files as $name => $file) {
// Skip directories (they would be added automatically)
if (!$file->isDir()) {
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath));
date_default_timezone_set("Asia/Singapore");
//touch($filePath, );
// Add current file to archive
$zip->addFile($filePath, $relativePath);
}
}
// Zip archive will be created only after closing object
$zip->close();
}
else {
echo "File not created.";
}

我会首先尝试在脚本的开头设置时区,在创建 ZIP 之前,而不是在 foreach 循环中。

但话虽如此,我不相信它会有太大区别,因为 PDF 文件已经存在?因此,已经将这些属性分配给了它们!

您是否有权访问虚拟主机管理器或类似内容?如果您有VPS或专用服务器,则可以自行更改服务器的时区。

编辑:抱歉,您已经声明您在共享服务器上,强烈建议使用VPS来完全控制这些设置,每月只需$ 50一个

最新更新