47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
function deleteDir($dirPath)
|
|
{
|
|
if (!is_dir($dirPath)) {
|
|
throw new InvalidArgumentException("$dirPath must be a directory");
|
|
}
|
|
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
|
|
$dirPath .= '/';
|
|
}
|
|
$files = glob($dirPath . '*', GLOB_MARK);
|
|
foreach ($files as $file) {
|
|
if (is_dir($file)) {
|
|
deleteDir($file);
|
|
} else {
|
|
unlink($file);
|
|
}
|
|
}
|
|
rmdir($dirPath);
|
|
}
|
|
|
|
function zipDir($pathdir, $zipcreated, $extensions = [])
|
|
{
|
|
// Create new zip class
|
|
$zip = new ZipArchive;
|
|
|
|
if($zip->open($pathdir . DIRECTORY_SEPARATOR . $zipcreated, (ZipArchive::CREATE)) === TRUE) {
|
|
|
|
// Store the path into the variable
|
|
$dir = opendir($pathdir);
|
|
|
|
while($file = readdir($dir)) {
|
|
$file_parts = pathinfo($pathdir . DIRECTORY_SEPARATOR . $file);
|
|
if ( ! in_array($file_parts['extension'], $extensions)) {
|
|
continue;
|
|
}
|
|
|
|
if(is_file($pathdir . DIRECTORY_SEPARATOR . $file)) {
|
|
$zip -> addFile($pathdir . DIRECTORY_SEPARATOR . $file, $file);
|
|
}
|
|
}
|
|
$zip ->close();
|
|
}
|
|
|
|
}
|