执行 php 解压缩文件的页面(操作文件)

execute php page that unzip a file (manipulate files)

我正在使用本地 (rhel 8) 服务器使用 php 解压缩文件(建议的解决方案:)

<?php
// assuming file.zip is in the same directory as the executing script.
$file = 'temperatures.zip';

// get the absolute path to $file
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);

$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
  // extract it to the path we determined above
  $zip->extractTo($path);
  $zip->close();
  echo "Success! $file extracted to $path";
} else {
  echo "Failled! I couldn't open $file";
}
?>

问题是:

注意:我试过使用 wamp 服务器,它可以工作,所以问题可能出在服务器上。

顺便说一下,所有操作文件的 php 行代码都没有生效。我通过允许 Apache 用户(rhel 中的apache)在目录中创建文件来解决这个问题。这可以通过使 Apache 成为目录 运行 的所有者来完成此命令:

sudo chown apache /var/www/html/