小编典典
我只能假设您的代码来自在线某个地方的教程?在这种情况下,请尝试自己解决这个问题。另一方面,该代码实际上可以在线发布为解压缩文件的正确方法,这有点令人恐惧。
PHP具有用于处理压缩文件的内置扩展。不需要为此使用system调用。ZipArchive_docs_是一种选择。
$zip = new ZipArchive;
$res = $zip->open('file.zip');
if ($res === TRUE) {
$zip->extractTo('/myzips/extract_path/');
$zip->close();
echo 'woot!';
} else {
echo 'doh!';
}
而且,正如其他人所评论的那样,$HTTP_GET_VARS自4.1版本起已弃用…
…很久以前。不要使用它。请改用$_GETsuperglobal。
最后,在接受通过$_GET变量传递给脚本的任何输入时要非常小心。
始终清理用户输入。
更新
根据您的评论,将zip文件提取到其所在目录中的最佳方法是确定该文件的硬路径并将其专门提取到该位置。因此,您可以执行以下操作:
// assuming file.zip is in the same directory as the executing script.
$file = 'file.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 "WOOT! $file extracted to $path";
} else {
echo "Doh! I couldn't open $file";
}
2020-05-26