开发者

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

$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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜