$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).
精彩评论