本文整理汇总了PHP中dir函数的典型用法代码示例。如果您正苦于以下问题:PHP dir函数的具体用法?PHP dir怎么用?PHP dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: copyr
function copyr($source, $dest)
{
if (is_link($source)) {
return symlink(readlink($source), $dest);
}
if (is_file($source)) {
$copied = copy($source, $dest);
$content = file_get_contents($dest);
$content = str_replace("Forone\\Admin\\Controllers", "App\\Http\\Controllers\\Forone\\Admin\\Controllers", $content);
file_put_contents($dest, $content);
return $copied;
}
if (!is_dir($dest)) {
mkdir($dest, 0777, true);
}
$dir = dir($source);
while (false !== ($entry = $dir->read())) {
if ($entry == '.' || $entry == '..') {
continue;
}
copyr("{$source}/{$entry}", "{$dest}/{$entry}");
}
$dir->close();
return true;
}
示例2: get_tests
public static function get_tests($root_file, $root_class, $add_skip = null)
{
$tests = array();
if (!isset($root_file) || !isset($root_class)) {
return $tests;
}
$skip = array('.', '..', 'all.php');
if (is_array($add_skip)) {
$skip = array_merge($skip, $add_skip);
}
$skip = array_flip($skip);
$path_parts = pathinfo($root_file);
$tests_dir = dir($path_parts['dirname']);
$prefix = str_replace('_all', '', $root_class);
while (($testfile = $tests_dir->read()) !== false) {
if (array_key_exists($testfile, $skip)) {
continue;
}
$path_parts = pathinfo($testfile);
$test_name = str_replace('.php', '', $path_parts['filename']);
$test_name = str_replace('Test', '', $test_name);
if ($test_name != '') {
require_once realpath(dirname($root_file)) . "/{$testfile}";
$tests[] = "{$prefix}_{$test_name}";
}
}
return $tests;
}
示例3: getimages
function getimages($dir)
{
global $imagetypes;
// array to hold return values;
$retval = array();
// add trailing slashes if missing;
if (substr($dir, -1) != "/") {
$dir .= "/images/";
}
// Full server path to dir
$fulldir = "{$_SERVER['DOCUMENT_ROOT']}/{$dir}";
// $fulldir ="localhost/novademo-localhost/images/";
$d = @dir($fulldir) or die("getimages: Failed opening directory {$_SERVER['DOCUMENT_ROOT']}/{$dir} for reading");
while (false != ($entry = $d->read())) {
// skip hidden files
if ($entry[0] == ".") {
continue;
}
// check for image files
$f = escapeshellarg("{$fulldir}" . "{$entry}");
$mimetype = trim(`file -bi {$f}`);
foreach ($imagetypes as $valid_type) {
if (preg_match("@^{$valid_type}@", $mimetype)) {
$retval[] = array('file' => "/{$dir}" . "{$entry}", 'size' => getimagesize("{$fulldir}" . "{$entry}"));
break;
}
}
}
$d->close();
return $retval;
}
示例4: getSkinNames
/**
* Fetch the set of available skins.
* @return array of strings
* @static
*/
static function getSkinNames()
{
global $wgValidSkinNames;
static $skinsInitialised = false;
if (!$skinsInitialised) {
# Get a list of available skins
# Build using the regular expression '^(.*).php$'
# Array keys are all lower case, array value keep the case used by filename
#
wfProfileIn(__METHOD__ . '-init');
global $wgStyleDirectory;
$skinDir = dir($wgStyleDirectory);
# while code from www.php.net
while (false !== ($file = $skinDir->read())) {
// Skip non-PHP files, hidden files, and '.dep' includes
$matches = array();
if (preg_match('/^([^.]*)\\.php$/', $file, $matches)) {
$aSkin = $matches[1];
$wgValidSkinNames[strtolower($aSkin)] = $aSkin;
}
}
$skinDir->close();
$skinsInitialised = true;
wfProfileOut(__METHOD__ . '-init');
}
return $wgValidSkinNames;
}
示例5: register
/**
* Loads ushahidi themes
*/
public function register()
{
// Array to hold all the CSS files
$theme_css = array();
// 1. Load the default theme
Kohana::config_set('core.modules', array_merge(array(THEMEPATH . "default"), Kohana::config("core.modules")));
$css_url = Kohana::config("cache.cdn_css") ? Kohana::config("cache.cdn_css") : url::base();
// HACK: don't include the default style.css if using the ccnz theme
if (Kohana::config("settings.site_style") != "ccnz") {
$theme_css[] = $css_url . "themes/default/css/style.css";
}
// 2. Extend the default theme
if (Kohana::config("settings.site_style") != "default") {
$theme = THEMEPATH . Kohana::config("settings.site_style");
Kohana::config_set('core.modules', array_merge(array($theme), Kohana::config("core.modules")));
if (is_dir($theme . '/css')) {
$css = dir($theme . '/css');
// Load all the themes css files
while (($css_file = $css->read()) !== FALSE) {
if (preg_match('/\\.css/i', $css_file)) {
$theme_css[] = url::base() . "themes/" . Kohana::config("settings.site_style") . "/css/" . $css_file;
}
}
}
}
Kohana::config_set('settings.site_style_css', $theme_css);
}
示例6: getMD5Hash
/**
* Function which will return the hash after passing through all folders and subfolders within it.
* @param $dir - Starting folder to scan
* @param $excludeFileList - List of filenames to exclude from scan
* @param $excludeExtensionList - List of extensions to exclude from scan
* @return Final MD5 of all files scanned.
*/
function getMD5Hash($dir, $excludeFileList, $excludeExtensionList)
{
if (!is_dir($dir)) {
return false;
}
$fileMD5list = array();
$d = dir($dir);
while (false !== ($entry = $d->read())) {
if ($entry != '.' && $entry != '..') {
if (is_dir($dir . '/' . $entry)) {
$fileMD5list[] = getMD5Hash($dir . '/' . $entry, $excludeFileList, $excludeExtensionList);
} else {
if (stripos($excludeFileList, $entry) === false) {
$extension = end(explode('.', $entry));
//get the file extension
if (stripos($excludeExtensionList, $extension) === false) {
$fileMD5list[] = md5_file($dir . '/' . $entry);
//Prepare list to MD5 only allowed
}
}
}
}
}
$d->close();
return md5(implode('', $fileMD5list));
//Return final MD5 of all files
}
示例7: xCopy
function xCopy($source, $destination, $child)
{
//用法:
// xCopy("feiy","feiy2",1):拷贝feiy下的文件到 feiy2,包括子目录
// xCopy("feiy","feiy2",0):拷贝feiy下的文件到 feiy2,不包括子目录
//参数说明:
// $source:源目录名
// $destination:目的目录名
// $child:复制时,是不是包含的子目录
if (!is_dir($source)) {
echo "Error:the {$source} is not a direction!";
return 0;
}
if (!is_dir($destination)) {
mkdir($destination, 0777);
}
$handle = dir($source);
while ($entry = $handle->read()) {
if ($entry != "." && $entry != "..") {
if (is_dir($source . "/" . $entry)) {
if ($child) {
xCopy($source . "/" . $entry, $destination . "/" . $entry, $child);
}
} else {
copy($source . "/" . $entry, $destination . "/" . $entry);
}
}
}
return 1;
}
示例8: getFilesMatchingPattern
/**
* Get a pattern and a directory, and returns an array of filenames matching the given pattern
*
* @param string $file_pattern
* @param string $current_dir
* @param boolean $recursively
* @return array An array of files matching the given pattern
*/
public static function getFilesMatchingPattern($file_pattern, $current_dir, $recursively = true)
{
$return_value = array();
if (is_readable($current_dir) && is_dir($current_dir)) {
$dir = dir($current_dir);
while (false !== ($file = $dir->read())) {
$current_file = $current_dir . DIRECTORY_SEPARATOR . $file;
$position_of_dot = strpos($file, ".");
if (is_readable($current_file) && $position_of_dot !== 0) {
if (is_file($current_file)) {
$file_matched = array();
if (preg_match('/^' . str_replace('*', '(.+?)', $file_pattern) . '$/', $file, $file_matched)) {
$return_value[strtoupper($current_file)] = $current_file;
}
} else {
if (is_dir($current_file) && $recursively) {
$return_value += self::getFilesMatchingPattern($file_pattern, $current_file);
}
}
}
}
} else {
throw new Exception('The directory ' . $current_dir . ' specified in the includepath does not exists or is not readable.');
}
return $return_value;
}
示例9: getType
function getType()
{
// first, get a list of a possible parent types
$templates = array();
$d = dir('include/SugarObjects/templates');
while ($filename = $d->read()) {
if (substr($filename, 0, 1) != '.') {
$templates[strtolower($filename)] = strtolower($filename);
}
}
// If a custom module, then its type is determined by the parent SugarObject that it extends
$type = $GLOBALS['beanList'][$this->module];
require_once $GLOBALS['beanFiles'][$type];
do {
$seed = new $type();
$type = get_parent_class($seed);
} while (!in_array(strtolower($type), $templates) && $type != 'SugarBean');
if ($type != 'SugarBean') {
return strtolower($type);
}
// If a standard module then just look up its type - type is implicit for standard modules. Perhaps one day we will make it explicit, just as we have done for custom modules...
$types = array('Accounts' => 'company', 'Bugs' => 'issue', 'Cases' => 'issue', 'Contacts' => 'person', 'Documents' => 'file', 'Leads' => 'person', 'Opportunities' => 'sale');
if (isset($types[$this->module])) {
return $types[$this->module];
}
return "basic";
}
示例10: xCopy
/**
* 复制文件夹(递归)到目标文件夹
**/
function xCopy($source, $destination)
{
if (substr($source, -1) == "/") {
$source = substr($source, 0, -1);
}
if (substr($destination, -1) == "/") {
$destination = substr($destination, 0, -1);
}
if (!is_dir($source)) {
return 0;
}
if (!is_dir($destination)) {
mkdir($destination, 0777);
}
$destination = $destination . "/" . basename($source);
if (!is_dir($destination)) {
mkdir($destination, 0777);
}
$handle = dir($source);
while ($entry = $handle->read()) {
if ($entry != "." && $entry != "..") {
if (is_dir($source . "/" . $entry)) {
xCopy($source . "/" . $entry, $destination);
} else {
copy($source . "/" . $entry, $destination . "/" . $entry);
}
}
}
return 1;
}
示例11: preDispatch
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$definePath = APPLICATION_PATH . '/modules/virtuemart/defines/';
$d = dir($definePath) or die("Wrong module path: {$definePath}");
while (false !== ($entry = $d->read())) {
if ($entry != '.' && $entry != '..' && !is_dir($definePath . $entry)) {
require_once $definePath . $entry;
}
}
$d->close();
// Tu dong autoload toan bo cac tai nguyen cua module
// $autoLoader = new Zend_Loader_Autoloader_Resource(array(
// 'basePath' => APPLICATION_PATH . '/modules/virtuemart',
// 'namespace' => '',
// 'resourceTypes' => array(
//// 'form' => array(
//// 'path' => 'admin/forms/',
//// 'namespace' => 'Admin_Form_',
//// ),
// 'model' => array(
// 'path' => 'models/',
// 'namespace' => DEFAULT_VM_NAMESPACE
// ),
// ),
// ));
}
示例12: loadTests
/**
* recurses through the Test subdir and includes classes in each test group subdir,
* then builds an array of classnames for the tests that will be run
*
*/
public function loadTests($test_path = NULL)
{
$this->resetStats();
if ($test_path === NULL) {
// this seems hackey. is it? dunno.
$test_path = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Security' . DIRECTORY_SEPARATOR . 'Test';
}
$test_root = dir($test_path);
while (false !== ($entry = $test_root->read())) {
if (is_dir($test_root->path . DIRECTORY_SEPARATOR . $entry) && !preg_match('|^\\.(.*)$|', $entry)) {
$test_dirs[] = $entry;
}
}
// include_once all files in each test dir
foreach ($test_dirs as $test_dir) {
$this_dir = dir($test_root->path . DIRECTORY_SEPARATOR . $test_dir);
while (false !== ($entry = $this_dir->read())) {
if (!is_dir($this_dir->path . DIRECTORY_SEPARATOR . $entry) && preg_match('/[A-Za-z]+\\.php/i', $entry)) {
$className = "Zend_Environment_Security_Test_" . $test_dir . "_" . basename($entry, '.php');
Zend::loadClass($className);
$classNames[] = $className;
}
}
}
$this->_tests_to_run = $classNames;
}
示例13: ReadAllProvider
function ReadAllProvider()
{
$dirName = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$handle = dir($dirName);
if ($handle === false) {
return;
}
while (false !== ($entry = $handle->read())) {
if (is_dir($entry)) {
continue;
}
if (!preg_match("/byjg\\.provider\\.(.*)\\.php/", $entry)) {
continue;
}
$providerName = substr($entry, strlen('byjg.provider.'), strlen($entry));
$providerName = substr($providerName, 0, strlen($providerName) - strlen('.php'));
if (empty($providerName)) {
continue;
}
if ($providerName == 'provider') {
continue;
}
require_once $entry;
$this->_providers[$providerName] = $entry;
}
}
示例14: clearFolderContent
function clearFolderContent($folder_path)
{
if (!file_exists($folder_path) or !is_dir($folder_path)) {
return false;
}
$folder_path = str_replace("\\", "/", realpath($folder_path));
if (_ml_substr($folder_path, -1, 1) != "/") {
$folder_path .= "/";
}
$folder = dir($folder_path);
while (($entry = $folder->read()) !== false) {
if ($entry == '..' or $entry == '.') {
continue;
}
if (is_dir($folder_path . $entry)) {
$this->clearFolderContent($folder_path . $entry);
@rmdir($folder_path . $entry);
}
if (is_file($folder_path . $entry)) {
@unlink($folder_path . $entry);
}
}
$folder->close();
return true;
}
示例15: execute
function execute(&$request)
{
if ($request['user']->isMember() && $request['user']->get('perms') >= ADMIN) {
$request['template']->setVar('current_location', $request['template']->getVar('L_FILEBROWSER'));
$request['template']->setVar('opener_input', @$_REQUEST['input']);
$request['template']->setVar('selected', @$_REQUEST['selected']);
$directory = BB_BASE_DIR . DIRECTORY_SEPARATOR . @$_REQUEST['dir'];
if (!isset($_REQUEST['dir']) || $_REQUEST['dir'] == '' || !file_exists($directory) || !is_dir($directory)) {
$action = new K4InformationAction(new K4LanguageElement('L_DIRECTORYDOESNTEXIST', BB_BASE_DIR . DIRECTORY_SEPARATOR . $dir), 'content', FALSE);
return $action->execute($request);
}
$filetypes = array('html' => array('HTM', 'HTML', 'JS'), 'php' => array('PHP'), 'img' => array('GIF', 'PNG', 'TIFF', 'JPG', 'JPEG', 'BMP', 'ICO'));
$filetype = (!isset($_REQUEST['filetype']) || $_REQUEST['filetype'] == '') && !array_key_exists(@$_REQUEST['filetype'], $filetypes) ? FALSE : $_REQUEST['filetype'];
$dir = dir($directory);
$files = array();
while (false !== ($file = $dir->read())) {
if ($file != '.' && $file != '..' && $file != 'Thumbs.db') {
if (!is_dir($directory . DIRECTORY_SEPARATOR . $file)) {
$temp = array();
/* Get File extension */
$exts = explode(".", $file);
$temp['fileext'] = count($exts) < 2 ? '' : strtoupper($exts[count($exts) - 1]);
$temp['shortname'] = $file;
$temp['filename'] = $_REQUEST['dir'] . '/' . $file;
$temp['file'] = $exts[0];
if (in_array($temp['fileext'], $filetypes['html'])) {
$temp['filetype'] = 'html';
} else {
if (in_array($temp['fileext'], $filetypes['php'])) {
$temp['filetype'] = 'php';
} else {
if (in_array($temp['fileext'], $filetypes['img'])) {
$temp['filetype'] = 'img';
$dimensions = $this->resize_image($temp['filename']);
$temp['width'] = $dimensions[0];
$temp['height'] = $dimensions[1];
} else {
$temp['filetype'] = '';
}
}
}
if (!$filetype) {
$files[] = $temp;
} else {
if ($temp['filetype'] == $filetype) {
$files[] = $temp;
}
}
}
}
}
$files =& new FAArrayIterator($files);
$request['template']->setVar('img', 'img');
$request['template']->setList('files_list', $files);
$request['template']->setFile('content', 'file_browser.html');
} else {
no_perms_error($request);
}
return TRUE;
}