本文整理汇总了PHP中Dir::getFiles方法的典型用法代码示例。如果您正苦于以下问题:PHP Dir::getFiles方法的具体用法?PHP Dir::getFiles怎么用?PHP Dir::getFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dir
的用法示例。
在下文中一共展示了Dir::getFiles方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: package
public static function package($source, $targetFile, $incParent = false)
{
// Make sure we're able to use the zip library
if (!extension_loaded('zip')) {
return false;
}
// Prepare the path
$source = str_replace('\\', '/', realpath($source));
// Make sure the file exists and is safe
if (!IsSanitized::filepath($source)) {
return false;
}
if (!file_exists($source)) {
return false;
}
// Make sure the directory exists
$targetDir = dirname($targetFile);
if (!is_dir($targetDir)) {
Dir::create($targetDir);
}
// Prepare the Zip Functionality
$zip = new ZipArchive();
if (!$zip->open($targetFile, ZIPARCHIVE::CREATE)) {
return false;
}
// Run the Zip Processer
if (is_dir($source) === true) {
$baseDir = '';
if ($incParent) {
$exp = explode("/", $source);
$baseDir = $exp[count($exp) - 1] . '/';
$zip->addEmptyDir($baseDir);
}
$files = Dir::getFiles($source, true, true);
foreach ($files as $file) {
if (is_dir($source . '/' . $file) === true) {
$zip->addEmptyDir($baseDir . $file);
} else {
if (is_file($source . '/' . $file) === true) {
$zip->addFile($source . '/' . $file, $baseDir . $file);
}
}
}
} else {
if (is_file($source) === true) {
$zip->addFile($file);
}
}
return $zip->close();
}
示例2: customErrorHandler
function customErrorHandler($errorNumber, $errorString, $errorFile, $errorLine)
{
// Prepare Values
$errorType = "Error";
switch ($errorNumber) {
case E_USER_NOTICE:
$errorType = "Notice";
$importance = 0;
break;
case E_USER_WARNING:
$errorType = "Warning";
$importance = 2;
break;
case E_USER_ERROR:
$errorType = "Fatal Error";
$importance = 4;
break;
default:
$errorType = "Unknown Error";
$importance = 8;
break;
}
// Run the Backtrace
$backtrace = debug_backtrace();
if (isset($backtrace[1])) {
// Prepare Backtrace Values
$origin = $backtrace[1];
$behind = $backtrace[0];
// Identify the current URL
$urlData = URL::parse($_SERVER['SERVER_NAME'] . "/" . $_SERVER['REQUEST_URI']);
// If the error was triggered with trigger_error(), simplify the logging
if ($origin['function'] == "trigger_error") {
// Prepare Logging Values
$class = "";
$function = "trigger_error";
$argString = $origin['args'][0];
$filePath = str_replace(SYS_PATH, "", $origin['file']);
$fileLine = (int) $origin['line'];
// Local Environment
if (ENVIRONMENT == "local") {
$cons = get_defined_constants(true);
$debugData = array("Backtrace" => array_splice($backtrace, 1), "URL" => $urlData, "Constants" => $cons['user'], "_GET" => $_GET, "_POST" => $_POST, "_COOKIE" => $_COOKIE, "_SESSION" => $_SESSION, "_SERVER" => $_SERVER);
}
} else {
// Prepare Logging Values
$class = isset($origin['class']) ? $origin['class'] : "";
$function = isset($origin['function']) ? $origin['function'] : "";
$argString = isset($origin['args']) ? Data_Utilities::convertArrayToArgumentString($origin['args']) : "";
$filePath = isset($behind['file']) ? str_replace(dirname(SYS_PATH), "", $behind['file']) : '';
$fileLine = isset($behind['line']) ? $behind['line'] : 0;
// Skip instances of the autoloader
if ($errorType == "Unknown Error" and strpos($function, "spl_autoload") !== false) {
return false;
}
}
// Debug files in the local environment
if (ENVIRONMENT == "local") {
if (!isset($urlData['path'])) {
$urlData['path'] = "home";
}
// Add an entry to the debug timeline
File::write(SYS_PATH . "/debug/" . microtime(true) . "-" . str_replace("/", "_", $urlData['path']) . ".php", print_r(isset($debugData) ? $debugData : $backtrace, true));
// Add an entry to the primary debug page
File::prepend(SYS_PATH . "/debug/_primaryDebug.php", print_r(array("Domain" => FULL_DOMAIN, "URL" => $urlData['full'], "Error" => $errorType . ": " . $argString, "File" => "[Line " . $fileLine . "] " . $filePath, "Timestamp" => microtime(true)), true));
// Add an entry to the debugging page
File::prepend(SYS_PATH . "/debug/by-site/" . FULL_DOMAIN . "/" . $urlData['path'] . ".php", print_r(array("URL" => $urlData['full'], "Error" => $errorType . ": " . $behind['args'][1], "File" => "[Line " . $fileLine . "] " . $filePath, "Timestamp" => microtime(true)), true));
// Prune the debug pages so that they don't get overloaded
File::prune(SYS_PATH . "/debug/_primaryDebug.php", 300);
File::prune(SYS_PATH . "/debug/by-site/" . FULL_DOMAIN . "/" . $urlData['path'] . ".php", 120);
// Prune the timeline debug files so that they don't exhaust the system
if (mt_rand(0, 25) == 22) {
$debugFiles = Dir::getFiles(SYS_PATH . "/debug");
foreach ($debugFiles as $dbf) {
if ($dbf[0] != "_") {
$exp = explode(".", $dbf);
if ($exp[0] < time() + 86400) {
File::delete(SYS_PATH . "/debug/" . $dbf);
} else {
break;
}
}
}
}
}
// Log this error in the database
// Debug::logError($importance, $errorType, $class, $function, $argString, $filePath, $fileLine, $urlData['full'], Me::$id);
// End the Error Handler
return false;
// TRUE to run standard error logging afterward
/*
if(ENVIRONMENT != "production")
{
Debug::$verbose = true;
Debug::scriptError($errorString, $class, $function, $argString, $filePath, $fileLine, $filePathNext, $fileLineNext);
}
else
{
return false;
}
//.........这里部分代码省略.........
示例3: importToDatabase
public static function importToDatabase($importDir)
{
// Prepare Values
$class = get_called_class();
$buildData = [];
$fileList = Dir::getFiles($importDir);
// Loop through each file and retrieve the contents
foreach ($fileList as $file) {
$fileContents = file_get_contents($importDir . '/' . $file);
$id = str_replace(".json", "", $file);
$buildData[$id] = json_decode($fileContents, true);
}
// Run the build process
static::build($buildData);
}
示例4: getAdminPages
public static function getAdminPages($classPath = "")
{
$controllerList = array();
// Get the admin pages for this class, if availble
if (is_dir($classPath . '/admin')) {
$contFiles = Dir::getFiles($classPath . '/admin');
foreach ($contFiles as $filename) {
if (strpos($filename, ".php") === false) {
continue;
}
$fileName = Sanitize::variable(str_replace(".php", "", $filename), " -");
$controllerList[] = $fileName;
}
}
return $controllerList;
}