本文整理汇总了PHP中glob函数的典型用法代码示例。如果您正苦于以下问题:PHP glob函数的具体用法?PHP glob怎么用?PHP glob使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了glob函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* {@inheritdoc}
*/
public function run()
{
if (is_null($this->dst) || "" === $this->dst) {
return Result::error($this, 'You must specify a destination file with to() method.');
}
if (!$this->checkResources($this->files, 'file')) {
return Result::error($this, 'Source files are missing!');
}
if (file_exists($this->dst) && !is_writable($this->dst)) {
return Result::error($this, 'Destination already exists and cannot be overwritten.');
}
$dump = '';
foreach ($this->files as $path) {
foreach (glob($path) as $file) {
$dump .= file_get_contents($file) . "\n";
}
}
$this->printTaskInfo('Writing {destination}', ['destination' => $this->dst]);
$dst = $this->dst . '.part';
$write_result = file_put_contents($dst, $dump);
if (false === $write_result) {
@unlink($dst);
return Result::error($this, 'File write failed.');
}
// Cannot be cross-volume; should always succeed.
@rename($dst, $this->dst);
return Result::success($this);
}
示例2: renderContent
public function renderContent($args, $setting)
{
$t = array('name' => '', 'image_folder_path' => '', 'limit' => 12, 'columns' => 4);
$protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
$url = Tools::htmlentitiesutf8($protocol . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__);
$setting = array_merge($t, $setting);
$oimages = array();
if ($setting['image_folder_path']) {
$path = _PS_ROOT_DIR_ . '/' . trim($setting['image_folder_path']) . '/';
$path = str_replace("//", "/", $path);
if (is_dir($path)) {
$images = glob($path . '*.*');
$exts = array('jpg', 'gif', 'png');
foreach ($images as $cnt => $image) {
$ext = Tools::substr($image, Tools::strlen($image) - 3, Tools::strlen($image));
if (in_array(Tools::strtolower($ext), $exts)) {
if ($cnt < (int) $setting['limit']) {
$i = str_replace("\\", "/", '' . $setting['image_folder_path'] . "/" . basename($image));
$i = str_replace("//", "/", $i);
$oimages[] = $url . $i;
}
}
}
}
}
$images = array();
$setting['images'] = $oimages;
$output = array('type' => 'image', 'data' => $setting);
return $output;
}
示例3: run
public static function run()
{
foreach (glob(app_path() . '/Http/Controllers/*.php') as $filename) {
$file_parts = explode('/', $filename);
$file = array_pop($file_parts);
$file = rtrim($file, '.php');
if ($file == 'Controller') {
continue;
}
$controllerName = 'App\\Http\\Controllers\\' . $file;
$controller = new $controllerName();
if (isset($controller->exclude) && $controller->exclude === true) {
continue;
}
$methods = [];
$reflector = new \ReflectionClass($controller);
foreach ($reflector->getMethods(\ReflectionMethod::IS_PUBLIC) as $rMethod) {
// check whether method is explicitly defined in this class
if ($rMethod->getDeclaringClass()->getName() == $reflector->getName()) {
$methods[] = $rMethod->getName();
}
}
\Route::resource(strtolower(str_replace('Controller', '', $file)), $file, ['only' => $methods]);
}
}
示例4: template
/**
* Compiles a template and writes it to a cache file, which is used for inclusion.
*
* @param string $file The full path to the template that will be compiled.
* @param array $options Options for compilation include:
* - `path`: Path where the compiled template should be written.
* - `fallback`: Boolean indicating that if the compilation failed for some
* reason (e.g. `path` is not writable), that the compiled template
* should still be returned and no exception be thrown.
* @return string The compiled template.
*/
public static function template($file, array $options = array())
{
$cachePath = Libraries::get(true, 'resources') . '/tmp/cache/templates';
$defaults = array('path' => $cachePath, 'fallback' => false);
$options += $defaults;
$stats = stat($file);
$oname = basename(dirname($file)) . '_' . basename($file, '.php');
$oname .= '_' . ($stats['ino'] ?: hash('md5', $file));
$template = "template_{$oname}_{$stats['mtime']}_{$stats['size']}.php";
$template = "{$options['path']}/{$template}";
if (file_exists($template)) {
return $template;
}
$compiled = static::compile(file_get_contents($file));
if (is_writable($cachePath) && file_put_contents($template, $compiled) !== false) {
foreach (glob("{$options['path']}/template_{$oname}_*.php", GLOB_NOSORT) as $expired) {
if ($expired !== $template) {
unlink($expired);
}
}
return $template;
}
if ($options['fallback']) {
return $file;
}
throw new TemplateException("Could not write compiled template `{$template}` to cache.");
}
示例5: rglob
function rglob($pattern, $files = 1, $dirs = 0, $flags = 0)
{
$dirname = dirname($pattern);
$basename = basename($pattern);
$glob = glob($pattern, $flags);
$files = array();
$dirlist = array();
foreach ($glob as $path) {
if (is_file($path) && !$files) {
continue;
}
if (is_dir($path)) {
$dirlist[] = $path;
if (!$dirs) {
continue;
}
}
$files[] = $path;
}
foreach (glob("{$dirname}/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
$dirfiles = rglob($dir . '/' . $basename, $files, $dirs, $flags);
$files = array_merge($files, $dirfiles);
}
return $files;
}
示例6: runUnitTests
public function runUnitTests($tests)
{
// Build any unit tests
$this->make('build-tests');
// Now find all the test programs
$root = $this->getProjectRoot();
$test_dir = $root . "/tests/";
$futures = array();
if (!$tests) {
$paths = glob($test_dir . "*.t");
} else {
$paths = array();
foreach ($tests as $path) {
$tpath = preg_replace('/\\.c$/', '.t', $path);
if (preg_match("/\\.c\$/", $path) && file_exists($tpath)) {
$paths[] = realpath($tpath);
}
}
}
foreach ($paths as $test) {
$relname = substr($test, strlen($test_dir));
$futures[$relname] = new ExecFuture($test);
}
$results = array();
$futures = new FutureIterator($futures);
foreach ($futures->limit(4) as $test => $future) {
list($err, $stdout, $stderr) = $future->resolve();
$results[] = $this->parseTestResults($test, $err, $stdout, $stderr);
}
return $results;
}
示例7: mbAutoload
/**
* Mediboard class autoloader
*
* @param string $class Class to be loaded
*
* @return bool
*/
function mbAutoload($class)
{
$file_exists = false;
$time = microtime(true);
// Entry already in cache
if (isset(CApp::$classPaths[$class])) {
// The class is known to not be in MB
if (CApp::$classPaths[$class] === false) {
return false;
}
// Load it if we can
if ($file_exists = file_exists(CApp::$classPaths[$class])) {
CApp::$performance["autoloadCount"]++;
return include_once CApp::$classPaths[$class];
}
}
// File moved ?
if (!$file_exists) {
unset(CApp::$classPaths[$class]);
}
// CSetup* class
if (preg_match('/^CSetup(.+)$/', $class, $matches)) {
$dirs = array("modules/{$matches['1']}/setup.php");
} else {
$class_file = $class;
$suffix = ".class";
// Namespaced class
if (strpos($class_file, "\\") !== false) {
$namespace = explode("\\", $class_file);
// Mediboard class
if ($namespace[0] === "Mediboard") {
array_shift($namespace);
$class_file = implode("/", $namespace);
} else {
$class_file = "vendor/" . implode("/", $namespace);
$suffix = "";
}
}
$class_file .= $suffix;
$dirs = array("classes/{$class_file}.php", "classes/*/{$class_file}.php", "mobile/*/{$class_file}.php", "modules/*/classes/{$class_file}.php", "modules/*/classes/*/{$class_file}.php", "modules/*/classes/*/*/{$class_file}.php", "install/classes/{$class_file}.php");
}
$rootDir = CAppUI::conf("root_dir");
$class_path = false;
foreach ($dirs as $dir) {
$files = glob("{$rootDir}/{$dir}");
foreach ($files as $filename) {
include_once $filename;
// The class was found
if (class_exists($class, false) || interface_exists($class, false)) {
$class_path = $filename;
break 2;
}
}
}
// Class not found, it is not in MB
CApp::$classPaths[$class] = $class_path;
SHM::put("class-paths", CApp::$classPaths);
CApp::$performance["autoload"][$class] = (microtime(true) - $time) * 1000;
return $class_path !== false;
}
示例8: loadAll
function loadAll($directory)
{
$directory = dirname(__FILE__) . "/../{$directory}";
foreach (glob("{$directory}/*.php") as $filename) {
require_once $filename;
}
}
示例9: load_classes
/**
* Scans the plugins subfolder and include files
*
* @since 05/02/2013
* @return void
*/
protected function load_classes()
{
// load required classes
foreach (glob(dirname(__FILE__) . '/inc/*.php') as $path) {
require_once $path;
}
}
示例10: getTodayImage
/**
* 取得今天要顯示的圖片
* @return 圖片的完整路徑 (含檔名)
* FALSE: 找不到圖片
**/
function getTodayImage($orgimg)
{
global $chroot, $imgext;
$dir = $chroot;
$now = date('Ymd');
$imglst = array();
foreach (array_keys($imgext) as $ext) {
foreach (glob($dir . "*.{$ext}") as $filename) {
$name = basename($filename, ".{$ext}");
if (!is_numeric($name) || strlen($name) != 8) {
continue;
}
if (strcmp($now, $name) < 0) {
continue;
}
$imglst[$name] = $filename;
}
}
if (count($imglst) <= 0) {
setCache($orgimg);
return FALSE;
} else {
krsort($imglst);
$img = array_shift($imglst);
setCache($img);
return $img;
}
}
示例11: pic_thumb
function pic_thumb($pic_id)
{
$this->load->helper('file');
$this->load->library('image_lib');
$base_path = "uploads/item_pics/" . $pic_id;
$images = glob($base_path . "*");
if (sizeof($images) > 0) {
$image_path = $images[0];
$ext = pathinfo($image_path, PATHINFO_EXTENSION);
$thumb_path = $base_path . $this->image_lib->thumb_marker . '.' . $ext;
if (sizeof($images) < 2) {
$config['image_library'] = 'gd2';
$config['source_image'] = $image_path;
$config['maintain_ratio'] = TRUE;
$config['create_thumb'] = TRUE;
$config['width'] = 52;
$config['height'] = 32;
$this->image_lib->initialize($config);
$image = $this->image_lib->resize();
$thumb_path = $this->image_lib->full_dst_path;
}
$this->output->set_content_type(get_mime_by_extension($thumb_path));
$this->output->set_output(file_get_contents($thumb_path));
}
}
示例12: template_list
/**
* 模板风格列表
* @param integer $siteid 站点ID,获取单个站点可使用的模板风格列表
* @param integer $disable 是否显示停用的{1:是,0:否}
*/
function template_list($siteid = '', $disable = 0)
{
$list = glob(PC_PATH . 'templates' . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR);
$arr = $template = array();
if ($siteid) {
$site = pc_base::load_app_class('sites', 'admin');
$info = $site->get_by_id($siteid);
if ($info['template']) {
$template = explode(',', $info['template']);
}
}
foreach ($list as $key => $v) {
$dirname = basename($v);
if ($siteid && !in_array($dirname, $template)) {
continue;
}
if (file_exists($v . DIRECTORY_SEPARATOR . 'config.php')) {
$arr[$key] = (include $v . DIRECTORY_SEPARATOR . 'config.php');
if (!$disable && isset($arr[$key]['disable']) && $arr[$key]['disable'] == 1) {
unset($arr[$key]);
continue;
}
} else {
$arr[$key]['name'] = $dirname;
}
$arr[$key]['dirname'] = $dirname;
}
return $arr;
}
示例13: indexAction
/**
* @Route("/", methods="GET")
* @Request({"folder": "string"})
*/
public function indexAction($folder = '')
{
$images = [];
$folder = trim($folder, '/');
$pttrn = '/\\.(jpg|jpeg|gif|png)$/i';
$dir = App::path();
if (!($files = glob($dir . '/' . $folder . '/*'))) {
return [];
}
foreach ($files as $img) {
// extension filter
if (!preg_match($pttrn, $img)) {
continue;
}
$data = array();
$data['filename'] = basename($img);
// remove extension
$data['title'] = preg_replace('/\\.[^.]+$/', '', $data['filename']);
// remove leading number
$data['title'] = preg_replace('/^\\d+\\s?+/', '', $data['title']);
// remove trailing numbers
$data['title'] = preg_replace('/\\s?+\\d+$/', '', $data['title']);
// replace underscores with space and add capital
$data['title'] = ucfirst(trim(str_replace(['_', '-'], ' ', $data['title'])));
$data['image']['src'] = $folder . '/' . basename($img);
$data['image']['alt'] = $data['title'];
$images[] = $data;
}
return $images;
}
示例14: getFieldTypes
/**
* @return array
*/
public function getFieldTypes($extension = null)
{
//todo cache this
if (!$this->fieldTypes) {
$this->fieldTypes = [];
/** @noinspection PhpUnusedLocalVariableInspection */
$app = App::getInstance();
//available for index.php files
$paths = [];
foreach (App::module() as $module) {
if ($module->get('fieldtypes')) {
$paths = array_merge($paths, glob(sprintf('%s/%s/*/index.php', $module->path, $module->get('fieldtypes')), GLOB_NOSORT) ?: []);
}
}
foreach ($paths as $p) {
$package = array_merge(['id' => '', 'path' => dirname($p), 'main' => '', 'extensions' => $this->fieldExtensions, 'class' => '\\Bixie\\Framework\\FieldType\\FieldType', 'resource' => 'bixie/framework:app/bundle', 'config' => ['hasOptions' => 0, 'readonlyOptions' => 0, 'required' => 0, 'multiple' => 0], 'dependancies' => [], 'styles' => [], 'getOptions' => '', 'prepareValue' => '', 'formatValue' => ''], include $p);
$this->registerFieldType($package);
}
}
if ($extension) {
return array_filter($this->fieldTypes, function ($fieldType) use($extension) {
/** @var FieldTypeBase $fieldType */
return in_array($extension, $fieldType->getExtensions());
});
}
return $this->fieldTypes;
}
示例15: index
public function index()
{
$dirs = glob(APP_PATH . C("APP_GROUP_PATH") . DIRECTORY_SEPARATOR . '*');
foreach ($dirs as $path) {
if (is_dir($path)) {
$path = basename($path);
$dirs_arr[] = $path;
}
}
//数量
$total = count($dirs_arr);
//把一个数组分割为新的数组块
$dirs_arr = array_chunk($dirs_arr, 20, true);
//当前分页
$page = max(intval($_GET['page']), 1);
$directory = $dirs_arr[intval($page - 1)];
$pages = $this->page($total, 20);
$modulesdata = M("Module")->select();
foreach ($modulesdata as $v) {
$modules[$v['module']] = $v;
}
$this->assign("Page", $pages->show("Admin"));
$this->assign("data", $directory);
$this->assign("modules", $modules);
$this->display();
}