/** * Recursive delete function * @param str path * @return bool */ public static function rm_r($path) { if (!is_link($path) && is_dir($path)) { $objects = scandir($src); if ($objects === false) { return false; } foreach ($objects as $file) { if ($file == "." || $file == "..") { continue; } if (!rm_r($path . DIRECTORY_SEPARATOR . $file)) { return false; } } return rmdir($path); } return unlink($path); }
function rmMeta($group, $subgroup = null, $leaf = null) { $c =& pfcGlobalConfig::Instance(); $dir = $c->container_cfg_server_dir; if ($group == NULL) { rm_r($dir); return true; } $dir .= '/' . $group; if ($subgroup == NULL) { rm_r($dir); return true; } $dir .= '/' . $subgroup; if ($leaf == NULL) { rm_r($dir); return true; } $leaffilename = $dir . '/' . $leaf; if (!file_exists($leaffilename)) { return false; } unlink($leaffilename); // check that the directory is empty or not // remove it if it doesn't contains anything $dh = opendir($dir); readdir($dh); readdir($dh); // skip . and .. directories $isnotempty = readdir($dh); closedir($dh); if ($isnotempty === false) { rmdir($dir); } return true; }
public static function rm_r($path) { if (is_dir($path) and $dh = opendir($path)) { while (($entry = readdir($dh)) !== false) { if (!preg_match('/\\A\\.\\.?\\z/', $entry)) { $p = $path . DIRECTORY_SEPARATOR . $entry; if (is_dir($p)) { rm_r($p); } else { unlink($p); } } } closedir($dh); rmdir($path); return true; } else { return false; } }
$qry4 = "UPDATE box SET create_date = activity_date \n WHERE box_id = LAST_INSERT_ID();"; $result4 = mysqli_query($link, $qry4); if (!$result4) { // If query failed $logMessage = 'MySQL Error 5: ' . mysqli_error($link); error_log($logMessage); unlink($imagedest); // Backout image directory change. echo $errResp; exit; } $qry5 = "SELECT LAST_INSERT_ID();"; $result5 = mysqli_query($link, $qry5); if (!$result5 || mysqli_num_rows($result5) !== 1) { $logMessage = 'MySQL Error 6: ' . mysqli_error($link); error_log($logMessage); unlink($imagedest); // Backout image directory change. echo $errResp; exit; } $arr5 = mysqli_fetch_array($result5); $boxid = $arr5[0]; // box_id $report->rpttext[] = "Game box successfully created."; $report->rpttext[] = " game box id = " . $boxid; } $fr = json_encode($report); echo "{$fr}"; rm_r('~/uploads/' . $dirAname); // Clear out game box directory.
function rm_r($dir) { if (!($dh = @opendir($dir))) { return; } while ($obj = readdir($dh)) { if ($obj == '.' || $obj == '..') { continue; } if (!@unlink($dir . '/' . $obj)) { rm_r($dir . '/' . $obj); } } closedir($dh); @rmdir($dir); }