gpt4 book ai didi

php - 如何在从 zip 文件解压缩到特定位置之前检查文件夹是否已经存在?

转载 作者:可可西里 更新时间:2023-10-31 23:44:02 31 4
gpt4 key购买 nike

$zipfile = 'zipfilename';
$extractpath= 'C:\extract';

$zip = new ZipArchive();

if ($zip->open($zipfile) !== TRUE) {
die ("Could not open archive");
}
// extract contents to destination directory
$zip->extractTo($extractpath);

如果文件夹已经存在,如何避免覆盖?

最佳答案

$extractpath = '/somewhere/someplace/';
if (is_dir($extractpath) AND file_exists($extractpath)) {
// Path exists
}

更新

Actually I want to avoid overwriting a folder while unzipping?

AFAIK,您不能覆盖文件夹。但是你可以覆盖一个文件。要查看目标文件是否已存在,请使用 file_exists() (与 is_file() 一起使用可能也是明智的)。

关于php - 如何在从 zip 文件解压缩到特定位置之前检查文件夹是否已经存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4283150/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com