开发者

how to check a folder already exists before extracting from zip file to a specific location?

开发者 https://www.devze.com 2023-01-27 14:14 出处:网络
$zipfile = \'zipfilename\'; $extractpath= \'C:\\extract\'; $zip = new ZipArchive(); if ($zip->open($zipfile) !== TRUE) {
$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开发者_运维问答);

How to avoid overwriting a folder if it already exist?


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

Update

Actually I want to avoid overwriting a folder while unzipping?

AFAIK, you can't overwrite a folder. But you can overwrite a file. To see if the destination file already exists, use file_exists() (using with is_file() is probably wise as well).

0

精彩评论

暂无评论...
验证码 换一张
取 消