function emptyDir($dirname)
{
    $dirStart = './core';
    $dirname = trim($dirname);
    // safeguards for snippet tester
    if (!is_dir("{$dirStart}/{$dirname}")) {
        exit('bad param for emptyDir()');
    }
    if (strpos($dirname, '..') !== false) {
        exit('bad param for emptyDir()');
    }
    // only allowed to remake subdirs inside core/
    if (realpath("{$dirStart}/{$dirname}") === realpath($dirStart)) {
        exit('bad param for emptyDir()');
    }
    $dir = "{$dirStart}/{$dirname}";
    $scan = scandir($dir);
    foreach ($scan as $i => $entry) {
        if ($entry === '.' || $entry === '..') {
            continue;
        }
        $fullPath = "{$dir}/{$entry}";
        if (is_file($fullPath)) {
            unlink($fullPath);
        }
        if (is_dir($fullPath)) {
            emptyDir("{$dirname}/{$entry}");
            rmdir($fullPath);
        }
    }
}
function emptyCache()
{
    global $manager;
    if ((bool) $_GET['emptycache'] == false) {
        return;
    }
    emptyDir($manager->clerk->getSetting("cache_path", 1));
    $manager->message(1, false, "Cache folder emptied!");
}
Example #3
0
/**
 * Empties a directory recursively.
 *
 * @param string $directory
 */
function emptyDir($directory)
{
    if (!is_dir($directory)) {
        return;
    }
    $iterator = new DirectoryIterator($directory);
    foreach ($iterator as $item) {
        if ($item->isFile() && $item->getFileName() !== 'placeholder' && $item->getFileName() !== '.gitempty' && $item->getFileName() !== '.gitkeep') {
            unlink($item->getPathname());
        }
        if ($item->isDir() && !$item->isDot() && $item->getFilename() !== "tmp" && $item->getFilename() !== "thumbs") {
            emptyDir($item->getPathname());
            rmdir($item->getPathname());
        }
    }
}
 /**
  * Will use this function to flush cache storage
  */
 function emptyDir($dirname = null)
 {
     if (!is_null($dirname)) {
         if (is_dir($dirname)) {
             if ($handle = @opendir($dirname)) {
                 while (($file = readdir($handle)) !== false) {
                     if ($file != "." && $file != "..") {
                         $fullpath = $dirname . '/' . $file;
                         if (is_dir($fullpath)) {
                             emptyDir($fullpath);
                             @rmdir($fullpath);
                         } else {
                             @unlink($fullpath);
                         }
                     }
                 }
                 closedir($handle);
             }
         }
     }
 }
function emptyDir($dir)
{
    $handle = opendir($dir);
    while (($fl = readdir($handle)) !== false) {
        $file = "{$dir}/{$fl}";
        if (!is_dir($file)) {
            unlink($file);
        } else {
            if ($fl != "." && $fl != "..") {
                $files = scandir($file);
                if (count($files) <= 2) {
                    rmdir($file);
                } else {
                    emptyDir($file);
                    rmdir($file);
                }
            }
        }
    }
    closedir($handle);
}
Example #6
0
 static function getRunInstallerForm()
 {
     global $controller;
     if (isset($_POST['startinstall']) && $_POST['startinstall'] == 'true') {
         //runtime_csfr::Protect();
         // set base vars
         $start = $_POST['startinstall'];
         $zipfile = $_POST['pkgzip'];
         $pkgInstall = $_POST['pkg'];
         $pkgdb = $_POST['pkgdb'];
         if ($start) {
             if (!isset($_POST['submit'])) {
                 if (isset($_SESSION['zpuid'])) {
                     $userid = $_SESSION['zpuid'];
                     $currentuser = ctrl_users::GetUserDetail($userid);
                     $hostdatadir = ctrl_options::GetOption('hosted_dir') . "" . $currentuser['username'];
                     $userName = $currentuser['username'];
                     $random = rand();
                     $sysOS = php_uname('s');
                     $line = "<h2>Preparing to install " . $pkgInstall . ":</h2>";
                     if (!isset($startinstall)) {
                         if ($pkgdb == "yes") {
                             $line .= "<font color=\"red\"><strong>This package requires a database and database user.</strong></font><br />";
                             $line .= "<a target=\"_blank\" href=\"../../../?module=mysql_databases\">&raquo;Open&laquo; </a> database manager.<br />";
                             $line .= "<a target=\"_blank\" href=\"../../../?module=mysql_users\">&raquo;Open&laquo; </a> database user manager.";
                             $line .= "<p>&nbsp;</p>";
                         }
                         $line .= "<p>Please provide the domain and folder name to start the installation of " . $pkgInstall . ".</p>";
                         $line .= "<form id=\"form\" name=\"doInstall\" action=\"/?module=sentastico\" method=\"post\">";
                         $line .= "<table>\n\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td align=\"right\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label for=\"site_domain\">Select domain: </label>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>";
                         $line .= "<td align=\"center\">";
                         $list = ListDomain($currentuser['userid']);
                         $line .= $list;
                         $line .= "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td align=\"right\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label for=\"install_to_base_dir\">Tick&nbsp;to&nbsp;install to&nbsp;domain&nbsp;root:</label>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td align=\"center\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"install_to_base_dir\" value=\"0\" />\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"checkbox\" onClick=\"if (this.checked) { document.getElementById('hiderow').style.display = 'none'; } else { document.getElementById('hiderow').style.display = ''; }\" name=\"install_to_base_dir\" value=\"1\" />\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<font size=\"-1\" color=\"red\"><strong>ALL FILES AND FOLDERS WILL BE DELETED!</strong></font>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<tr id=\"hiderow\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td align=\"right\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label for=\"dir_to_install\">Install To Sub-Folder: public_html/[domain]/</label>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"text\" name=\"dir_to_install\" style=\"width: 300px\"/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<font color=\"red\">NOTE:</font> For multiple subfolders use: subfolder/subsubfolder\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td colspan=\"3\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>&nbsp;</p>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td colspan=\"2\" class=\"button-align\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<!-- inputs -->\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"startinstall\" value=\"true\"> \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"u\" value=" . $currentuser['userid'] . "> \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"pkgzip\" value=" . $zipfile . "> \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"pkg\" value='" . $pkgInstall . "'> \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"pkgdb\" value=" . $_POST['pkgdb'] . ">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<button class=\"btn btn-danger btn-small\" type=\"submit\" name=\"submit\" value=\"Install\" onclick=\"\$('#loading').show();\">Install</button>&nbsp;&nbsp;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<button class=\"btn btn-danger btn-small\" type=\"button\" name=\"cancel\" value=\"Cancel\" onClick=\"javascript:location.href='?module=sentastico'\">Cancel</button>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t\t\t\t\t\t\t\t   </tr>\n\t\t\t\t\t\t\t\t\t\t\t</table>";
                         $line .= "</form>";
                         $line .= "<div id=\"loading\" style=\"display:none;\">\n\t\t\t\t\t\t\t\t\t\t\t\tPlease wait...<br />\n\t\t\t\t\t\t\t\t\t\t\t\t<img src=\"modules/sentastico/assets/bar.gif\" alt=\"\" /><br />\n\t\t\t\t\t\t\t\t\t\t\t\tUnpacking " . $pkgInstall . "...\n\t\t\t\t\t\t\t\t\t\t\t</div>";
                     }
                 }
             } else {
                 $userid = $_POST['u'];
                 $installed = @$_SESSION['installed'];
                 $install_to_base_dir = $_POST['install_to_base_dir'];
                 $currentuser = ctrl_users::GetUserDetail($userid);
                 $hostdatadir = ctrl_options::GetOption('hosted_dir') . "" . $currentuser['username'];
                 $site_domain = clean($_POST['site_domain']);
                 $dir_to_install = clean($_POST['dir_to_install']);
                 $install_to_base_dir = clean($_POST['install_to_base_dir']);
                 // Retrieve the directory for the Domain selected
                 $domaindir = FetchDomainDir($userid, $site_domain);
                 $completedir = $hostdatadir . "/public_html" . $domaindir . "/" . $dir_to_install . "";
                 $line = "<h2>Automated " . $pkgInstall . " Installation Status:</h2>";
                 if (file_exists($completedir) && $install_to_base_dir != '1' && empty($dir_to_install) && $installed != 'true') {
                     $line .= "If not empty root folder<br><br>";
                     $line .= "<p><font color=\"red\"><strong>Destination folder already exists!</strong></font><br /><br />Sorry, the install folder (<strong>/public_html" . $domaindir . "/" . $dir_to_install . "</strong>) already exists or contains files.<br />Please go back and create a new folder.</p>";
                     $line .= "<p><button class=\"btn btn-danger btn-small\" type=\"button\" onClick=\"javascript:location.href='?module=sentastico'\">Start over</button></p>";
                     // START issue here with showing folder exists even if folder created upon unzip completion
                 } else {
                     if (file_exists($completedir) && $install_to_base_dir != '1' && isset($dir_to_install) && $installed != 'true') {
                         $line .= "If not empty sub folder<br><br>";
                         $line .= "<p><font color=\"red\"><strong>Destination folder already exists!</strong></font><br /><br />Sorry, the install folder (<strong>/public_html" . $domaindir . "/" . $dir_to_install . "</strong>) already exists or contains files.<br />Please go back and create a new folder.</p>";
                         $line .= "<p><button class=\"btn btn-danger btn-small\" type=\"button\" onClick=\"javascript:location.href='?module=sentastico'\">Start over</button></p>";
                         // START issue here with showing folder exists even if folder created upon unzip completion
                     } else {
                         $line .= "Preparing folder: ";
                         CreateDir($completedir, $domaindir, $dir_to_install);
                         $line .= "<font color=\"green\">Folder created Successfully!</font>";
                         sleep(1);
                         // Remove all Files in the install Folder
                         emptyDir($completedir);
                         sleep(3);
                         set_time_limit(0);
                         $line .= "<br />Installing files: ";
                         $line .= "<form><input type='hidden' name='installed' value='InS'></form>";
                         // Un-Compressing The ZIP Archive
                         if (UnZip($zipfile . ".zip", $completedir, $site_domain, $dir_to_install) == 'true') {
                             $line .= "<font color=\"green\">Unzip was successful</font><br />";
                             $line .= "Package unzipped to: http://" . $site_domain . "/" . $dir_to_install . "<br /><br />";
                             if (file_exists($completedir . "/sentastico-install.php")) {
                                 $line .= "<a target=\"_blank\" href='http://" . $site_domain . "/" . $dir_to_install . "/sentastico-install.php'> <button class=\"btn btn-primary btn-small\" type=\"button\">Install Now</button> </a>";
                                 $line .= "<button class=\"btn btn-danger btn-small\" onClick=\"javascript:location.href='?module=sentastico'\">Install Later</button>";
                             } else {
                                 $line .= "<a target=\"_blank\" href='http://" . $site_domain . "/" . $dir_to_install . "/'><button class=\"btn btn-primary btn-small\" type=\"button\" onClick=\"javascript:location.href='?module=sentastico'\">Install Now</button></a>&nbsp;&nbsp;";
                                 $line .= "<button class=\"btn btn-danger btn-small\" onClick=\"javascript:location.href='?module=sentastico'\">Install Later</button>";
                             }
                         } else {
                             $line .= "<font color=\"red\">Unzip was not successful</font><br /><br />";
                             $line .= "<p><button class=\"btn btn-danger btn-small\" type=\"button\" onClick=\"javascript:location.href='?module=sentastico'\">Start over</button></p>";
                         }
                         $_SESSION['installed'] = 'true';
                         sleep(5);
                         // Set file/folder ownership and permissions if on posix
                         if (php_uname('s') != 'Windows NT') {
                             $line .= "Setting file and folder permissions: " . php_uname('s');
                             fixPermissions($completedir);
                         }
                     }
                 }
             }
         }
         return $line;
     }
 }
 /**
  * Recursive copy
  * @param string $sSourcePath
  * @param string $sDestinationPath
  * @throws \InvalidArgumentException
  */
 function rcopy($sSourcePath, $sDestinationPath)
 {
     if (!file_exists($sSourcePath)) {
         throw new \InvalidArgumentException('Source file "' . $sSourcePath . '" does not exist');
     }
     //Remove destination
     if (is_dir($sDestinationPath)) {
         emptyDir($sDestinationPath);
         if (!rmdir($sDestinationPath)) {
             $aLastError = error_get_last();
             throw new \RuntimeException('Unable to remove directory "' . $sDestinationPath . '" - ' . $aLastError['message']);
         }
     } elseif (is_file($sDestinationPath) && !@unlink($sDestinationPath)) {
         $aLastError = error_get_last();
         throw new \RuntimeException('Unable to remove file "' . $sDestinationPath . '" - ' . $aLastError['message']);
     }
     //Copy directory
     if (is_dir($sSourcePath)) {
         if (!mkdir($sDestinationPath, 0777, true)) {
             throw new \InvalidArgumentException('Destination directory "' . $sDestinationPath . '" can\'t be created');
         }
         foreach (scandir($sSourcePath) as $sFileName) {
             if ($sFileName != '.' && $sFileName != '..') {
                 rcopy($sSourcePath . DIRECTORY_SEPARATOR . $sFileName, $sDestinationPath . DIRECTORY_SEPARATOR . $sFileName);
             }
         }
     } elseif (!copy($sSourcePath, $sDestinationPath)) {
         throw new \RuntimeException(sprintf('"%s" can\'t by moved in "%s"', $sSourcePath, $sDestinationPath));
     }
 }
Example #8
0
         if ($game->downloadBinaries($dirToWrite)) {
             $i++;
             $xmlContent = $game->genXML();
             writeXML($xmlContent, $dirToWrite . "/meta/" . $xmlFile);
             $ds = writeZIP($dirToWrite, $contentId, $game->getVersion());
             if ($primera_version) {
                 /*echo '<h2>Subir este zip PRIMERO</h2>';
                   echo "<div style=\"margin: 0 auto; text-align: center; font-size: 20px\">Nombre del Zip generado <a href='".$ds['path']."'>".$ds['path']."</a>, <b>".$ds['size']."</b></div><br/>\n";
                   */
                 $main_zip = $ds['path'];
             } else {
                 $zips_generados[] = $ds;
                 //         echo "<div style=\"margin: 0 auto; text-align: center; font-size: 20px\">
                 //               Nombre del Zip generado ".$ds['path']."<b>".$ds['size']."</b></div><br/>\n";
             }
             emptyDir($dirToWrite);
         } else {
             echo '<li>ERROR al descargar binarios, zip no generado...</li>';
         }
     } catch (Exception $e) {
         $log .= "genXML: " . $e->getMessage() . "<br/>";
     }
     $totalCont++;
     $primera_version = false;
     $version += 0.1;
 }
 echo '<li><h1>Zip principal (subir este primero): <a href="' . $main_zip . '">Descargar</a></h1></li>';
 echo '<li><h1>Generando paquetes de Zips...</h1></li>';
 $tam_actual = 0;
 $nro_paquete = 0;
 $zip_a_empaquetar = array();
            foreach ($columns as $i => $col) {
                if (isset($line[$i])) {
                    $row[$col] = $line[$i];
                } else {
                    $row[$col] = '';
                }
            }
            $fileData[] = $row;
        }
    }
    return $fileData;
}
$dirEnd = 'appendVsWrite';
$dir = "core/{$dirEnd}";
if (is_dir($dir)) {
    emptyDir($dirEnd);
} else {
    mkdir($dir, 0777, true);
}
// skipping benchmarks, individual files are infeasible due to storage size
/*
$repeatedColHeader = 'AAA AAA AAA AAA AAA';
$repeatedData      = 'BBB BBB BBB BBB BBB';

$rowCounts = array(1, 10, 100, 1000);
$colCounts = array(1, 10, 100, 1000);

foreach ($colCounts as $colCount) {
    foreach ($rowCounts as $rowCount) {
        $data = array();
        $dataRow = array();
function upload_0($sid, $uploadTimestamp, $fileType, $excelFileMode, $dbType)
{
    $_SESSION["excelFileMode_{$sid}"] = $excelFileMode;
    // check file type
    $explodeRes = explode(".", $_FILES["upload_file"]["name"]);
    $extension = end($explodeRes);
    $mimes = array('xls', 'xlsx', 'csv', 'sql', 'zip');
    if (count($_FILES) <= 0) {
        $error = "ERROR: No file was uploaded.";
        $_SESSION["upload_file_{$sid}"]['error'] = $error;
    } else {
        if (!in_array($extension, $mimes)) {
            $error = "ERROR: please upload excel, csv, sql, or zip file.";
            $_SESSION["upload_file_{$sid}"]['error'] = $error;
        } else {
            //save upload file
            if ($_FILES['upload_file']['error'] > 0) {
                $error = "ERROR: " . $_FILES['upload_file']['error'] . "</br>";
                $_SESSION["upload_file_{$sid}"]['error'] = $_FILES['upload_file']['error'];
            } else {
                $upload_dir = mnmpath . "upload_raw_data/{$sid}/";
                if (!file_exists($upload_dir)) {
                    mkdir($upload_dir);
                }
                // Delete former files if user upload more than one time.
                if (isset($_SESSION["uploadTimestamp_{$sid}"]) && $_SESSION["uploadTimestamp_{$sid}"] != $uploadTimestamp) {
                    emptyDir($upload_dir);
                }
                $_SESSION["uploadTimestamp_{$sid}"] = $uploadTimestamp;
                // the file name that should be uploaded
                $file_tmp = $_FILES['upload_file']['tmp_name'];
                $raw_file_name = $_FILES['upload_file']['name'];
                $ext = pathinfo($raw_file_name, PATHINFO_EXTENSION);
                $_SESSION["fileExt_{$sid}"] = $ext;
                $upload_path = $upload_dir . $raw_file_name;
                // check upload status
                if (!move_uploaded_file($file_tmp, $upload_path)) {
                    $error = "ERROR: failed to save file.";
                    $_SESSION["upload_file_{$sid}"]['error'] = $_FILES['upload_file']['error'];
                } else {
                    // If a csv file is provided, create a excel file and write the csv value to it.
                    if (strtolower($ext) == 'csv') {
                        // $csvFilePath = $upload_path;
                        // $xlsxFilePath = FileUtil::convertCSVtoXLSX($csvFilePath);
                        // $xlsxFileName = pathinfo($xlsxFilePath, PATHINFO_BASENAME);
                        // $raw_file_name = $xlsxFileName;
                        //unlink($csvFilePath);
                    } else {
                        if (strtolower($ext) == 'zip') {
                            $_SESSION["excelFileMode_{$sid}"] = "append";
                            // If a zip file is provided, unzip all files.
                            $zipFilePath = $upload_path;
                            $zip = new ZipArchive();
                            $res = $zip->open($zipFilePath);
                            if ($res === TRUE) {
                                $zip->extractTo($upload_dir);
                                $zip->close();
                            } else {
                                $error = "ERROR: failed to unzip file.";
                                $_SESSION["upload_file_{$sid}"]['error'] = $error;
                            }
                            // Convert all csv files into xlsx files.
                            $dirFiles = scandir($upload_dir);
                            $i = 1;
                            foreach ($dirFiles as $filename) {
                                $filePath = $upload_dir . $filename;
                                if (FileUtil::isCSVFile($filePath)) {
                                    $_SESSION["fileExt_{$sid}"] = "csv";
                                    break;
                                    // $newFilePath = $upload_dir . $i++ . '.csv';
                                    // rename($filePath, $newFilePath);
                                    // $filePath = $newFilePath;
                                    // $csvFilePath = $filePath;
                                    // $xlsxFilePath = FileUtil::convertCSVtoXLSX($csvFilePath);
                                    // $xlsxFileName = pathinfo($xlsxFilePath, PATHINFO_BASENAME);
                                }
                                //unlink($filePath);
                            }
                        } else {
                            if (strtolower($ext) == 'sql') {
                                try {
                                    $dbImporter = DatabaseImporterFactory::createDatabaseImporter($dbType, $sid, my_pligg_base_no_slash);
                                    $dbImporter->importDbSchema($upload_path);
                                    // Store dump file path for the last step.
                                    $_SESSION["dump_file_{$sid}"] = $upload_path;
                                } catch (Exception $e) {
                                    $_SESSION["upload_file_{$sid}"]['error'] = $e->getMessage();
                                }
                            }
                        }
                    }
                    $loc_msg = "uploaded successfully";
                    $_SESSION["upload_file_{$sid}"]['loc'] = $loc_msg;
                }
            }
        }
    }
    $json_response = array();
    if (isset($_SESSION["upload_file_{$sid}"]['error'])) {
        $json_response['isSuccessful'] = false;
        $json_response['message'] = $_SESSION["upload_file_{$sid}"]['error'];
    } else {
        $json_response['isSuccessful'] = true;
        $json_response['message'] = $_SESSION["upload_file_{$sid}"]['loc'];
    }
    unset($_SESSION["upload_file_{$sid}"]['error']);
    unset($_SESSION["upload_file_{$sid}"]['loc']);
    echo json_encode($json_response);
}
Example #11
0
function emptyDir($dir, $includeSelf = false)
{
    if (!file_exists($dir)) {
        return true;
    }
    if (!is_dir($dir) || is_link($dir)) {
        return unlink($dir);
    }
    foreach (scandir($dir) as $item) {
        if ($item == '.' || $item == '..') {
            continue;
        }
        if (!emptyDir($dir . "/" . $item, true)) {
            @chmod($dir . "/" . $item, 0777);
            if (!emptyDir($dir . "/" . $item, true)) {
                return false;
            }
        }
    }
    return $includeSelf ? rmdir($dir) : true;
}
Example #12
0
/**
 * 删除目录
 * @param String $dir
 * @return boolean
 */
function zUnlink($dir)
{
    $handle = opendir($dir);
    while (false !== ($file = readdir($handle))) {
        if ($file == '.' || $file == '..') {
            continue;
        }
        $filename = $dir . DS . $file;
        if (filetype($filename) == 'dir') {
            zUnlink($filename);
        } else {
            unlink($filename);
        }
    }
    closedir($handle);
    if (emptyDir($dir)) {
        rmdir($dir);
    }
    return true;
}