加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 22:29:22 所属栏目:PHP教程 来源:网络整理
导读:$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); 如果已经存在,如何避
$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()也可能是明智的).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读