Answers for "PHP unzip file into directory, change unzipped folder's name"

0

PHP unzip file into directory, change unzipped folder's name

$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;
}
Posted by: Guest on June-17-2021

Browse Popular Code Answers by Language