PHP unzip file into directory, change unzipped folders name

72

$zipFile = "test.zip";
$fnNoExt = basename($zipFile, ".zip");
$date = new DateTime();
$now = $date->getTimestamp();
$destinationFolder = "/some/path/$fnNoExt-$now";

$zip = new ZipArchive;
if ($zip->open($zipFile, ZipArchive::CREATE) === TRUE) {
    if(!is_dir($destinationFolder)){
        mkdir($destinationFolder,  0777);
    }
    $zip->extractTo($destinationFolder);
    $zip->close();
} else {
    return FALSE;
}

Comments

Submit
0 Comments