php - 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 文件已经存在而产生很大的不同?因此已经将这些属性分配给了它们!
您可以访问 Web Host Manager 或类似的吗?如果您有 VPS 或专用服务器,您可以自己更改服务器的时区。
编辑:抱歉,您已经声明您在共享服务器上,强烈建议您使用 VPS 来完全控制这些设置,每月只需 50 美元
推荐阅读
- python - selenium.common.exceptions.WebDriverException:消息:尝试使用 Selenium 和 Python 单击元素时无法将数据转换为对象
- vue.js - 在自定义渲染中单击单元格时,引导 vue 获取行数据
- c++ - 鉴于这个例子,与使用多个线程或进程相比,我从轮询设计中得到什么好处?
- php - PHP iconv 函数 - 删除字符串中第一个 unicode 字符之后的所有字符串
- c# - ServiceStack 错误调用 Request.GetRawBody();
- sql-server - SSMS - 尝试批量插入表格,但小数字段有时包含 NA
- kubernetes - kubectl - 列出所有服务的所有端口转发?
- javascript - 在 Javascript 中保留本地日期时间
- java - 基于环境变量的spring boot自动配置
- visual-studio-code - 我可以在 VS Code 中添加水平标尺吗?