本文整理汇总了PHP中dir类的典型用法代码示例。如果您正苦于以下问题:PHP dir类的具体用法?PHP dir怎么用?PHP dir使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了dir类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read
public function read($url = '', $recursive = false, $format = 'flat')
{
if (substr($url, -1) !== Application::DS) {
$url .= Application::DS;
}
if ($this->ignore('find', $url)) {
return array();
}
$list = array();
$cwd = getcwd();
chdir($url);
if ($handle = opendir($url)) {
while (false !== ($entry = readdir($handle))) {
$recursiveList = array();
if ($entry == '.' || $entry == '..') {
continue;
}
$file = new stdClass();
$file->url = $url . $entry;
if (is_dir($file->url)) {
$file->url .= Application::DS;
$file->type = 'dir';
}
if ($this->ignore('find', $file->url)) {
continue;
}
$file->name = $entry;
if (isset($file->type)) {
if (!empty($recursive)) {
$directory = new dir();
$directory->ignore('list', $this->ignore());
$recursiveList = $directory->read($file->url, $recursive, $format);
if ($format !== 'flat') {
$file->list = $recursiveList;
unset($recursiveList);
}
}
} else {
$file->type = 'file';
}
if (is_link($entry)) {
$file->link = true;
}
/* absolute url is_link wont work probably the targeting type
if(is_link($file->url)){
$file->link = true;
}
*/
$list[] = $file;
if (!empty($recursiveList)) {
foreach ($recursiveList as $recursive_nr => $recursive_file) {
$list[] = $recursive_file;
}
}
}
}
closedir($handle);
return $list;
}
示例2: uninstall
protected function uninstall($plugin, $output)
{
$root = $this->kirby()->roots()->plugins() . DS . $plugin;
dir::remove($root);
$output->writeln('<comment>The "' . $plugin . '" plugin has been removed!</comment>');
$output->writeln('');
}
示例3: deleteFile
public static function deleteFile($id)
{
$values = [];
for ($i = 1; $i <= 10; $i++) {
$values[] = '`media' . $i . '` = ' . $id;
}
for ($i = 1; $i <= 10; $i++) {
$values[] = '`medialist' . $i . '` LIKE "%|' . $id . '|%"';
}
$sql = sql::factory();
$sql->query('SELECT id FROM ' . sql::table('structure_area') . ' WHERE ' . implode(' OR ', $values))->result();
if ($sql->num()) {
echo message::warning(lang::get('file_in_use'));
} else {
$sql = sql::factory();
$sql->setTable('media');
$sql->setWhere('id=' . $id);
$sql->select('filename');
$sql->result();
if (unlink(dir::media($sql->get('filename')))) {
$sql->delete();
return message::success(lang::get('file_deleted'), true);
} else {
return message::warning(sprintf(lang::get('file_not_deleted'), dyn::get('hp_url'), $sql->get('filename')), true);
}
}
}
示例4: uninstall
static function uninstall()
{
graphics::remove_rules("watermark");
module::delete("watermark");
Database::instance()->query("DROP TABLE `watermarks`");
dir::unlink(VARPATH . "modules/watermark");
}
示例5: __construct
public function __construct($params = array())
{
$defaults = array('page' => page(), 'headline' => 'Mentions');
if (is_a($params, 'Page')) {
$params = array('page' => $params);
} else {
if (is_string($params)) {
$params = array('headline' => $params);
}
}
$this->options = array_merge($defaults, $params);
$this->page = $this->options['page'];
$this->root = $this->page->root() . DS . '.webmentions';
$this->headline = new Field($this->page, 'headline', $this->options['headline']);
if (!is_dir($this->root)) {
return;
}
$files = dir::read($this->root);
// flip direction
rsort($files);
foreach ($files as $file) {
// skip the pings cache
if ($file == 'pings.json') {
continue;
}
// register a new webmention
try {
$mention = new Mention($this->page, $this->root . DS . $file);
$this->append($mention->id(), $mention);
} catch (Exception $e) {
}
}
}
示例6: checkAvatars
protected function checkAvatars()
{
$root = kirby()->roots()->avatars();
// try to create the avatars folder
dir::make($root);
return is_writable($root);
}
示例7: _clean_up
function _clean_up()
{
parent::_clean_up();
dir::rm(MEDIA_DIR);
$this->db->sql_delete('file_object');
$this->db->sql_delete('media');
}
示例8: write
function write($log_file_data, $string)
{
$log_dir = $log_file_data[0];
$log_name = $log_file_data[1];
$file_name = $log_dir . $log_name;
if (!is_dir($log_dir)) {
dir::mkdir($log_dir, 0775, true);
}
$oldumask = @umask(0);
$file_existed = @file_exists($file_name);
$log_file = @fopen($file_name, 'a');
if ($log_file) {
$time = strftime("%b %d %Y %H:%M:%S", strtotime('now'));
$notice = '[ ' . $time . " ]\n";
if ($user_id = user::get_id()) {
$notice .= '[ ' . $user_id . ' ] [ ' . user::get_login() . ' ] [ ' . user::get_email() . ' ] ';
}
$notice .= '[' . sys::client_ip() . '] [' . (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') . "]\n" . $string . "\n\n";
@fwrite($log_file, $notice);
@fclose($log_file);
if (!$file_existed) {
@chmod($file_name, 0664);
}
@umask($oldumask);
$result = true;
} else {
@umask($oldumask);
$result = false;
debug::write_error("Cannot open log file '{$file_name}' for writing\n" . "The web server must be allowed to modify the file.\n" . "File logging for '{$file_name}' is disabled.", __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, false);
}
return $result;
}
示例9: _update_media_record
function _update_media_record($id, $tmp_file_path, $file_name, $mime_type)
{
if (!file_exists($tmp_file_path)) {
debug::write_error('file doesnt exist', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('tmp' => $tmp_file_path));
return false;
}
if (function_exists('md5_file')) {
$etag = md5_file($tmp_file_path);
} else {
$fd = fopen($data['tmp_name'], 'rb');
$contents = fread($fd, filesize($tmp_file_path));
fclose($fd);
$etag = md5($contents);
}
if (!is_dir(MEDIA_DIR)) {
dir::mkdir(MEDIA_DIR, 777, true);
}
if (!copy($tmp_file_path, MEDIA_DIR . $id . '.media')) {
debug::write_error('temporary file copy failed', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('src' => $tmp_file_path, 'dst' => MEDIA_DIR . $id . '.media'));
return false;
}
$media_db_table = db_table_factory::instance('media');
$media_db_table->update_by_id($id, array('file_name' => $file_name, 'mime_type' => $mime_type, 'size' => filesize($tmp_file_path), 'etag' => $etag));
return true;
}
示例10: getUnInstalled
public function getUnInstalled()
{
$installed = (array) $this->getInstalled();
$folders = dir::folders(ZPATH_MODULES, '.', false);
$folders = array_diff($folders, array_keys($installed));
$modules = array();
foreach ($folders as $folder) {
$modulePath = ZPATH_MODULES . DS . $folder;
$moduleUrl = url::modules() . '/' . $folder;
$moduleFile = $modulePath . DS . 'module.php';
if (file::exists($moduleFile)) {
$m = (include $moduleFile);
$m['path'] = '$modules/' . $folder;
$m['url'] = '$modules/' . $folder;
if (!isset($m['icon'])) {
if (!file::exists($modulePath . '/icon.png')) {
$m['icon'] = url::theme() . '/image/skin/none.png';
} else {
$m['icon'] = $moduleUrl . '/icon.png';
}
}
$modules[$m['id']] = $m;
}
}
return $modules;
}
示例11: autoloader
/**
* Die eigentliche Funktion des Autoloader
*
* @param string $class Der Klassennamen
* @return bool
*/
public static function autoloader($class)
{
if (self::classExists($class)) {
return true;
}
preg_match_all("/(?:^|[A-Z])[a-z]+/", $class, $treffer);
$classPath = implode(DIRECTORY_SEPARATOR, array_map('strtolower', $treffer[0]));
if (isset(self::$classes[$class])) {
if (is_readable(self::$classes[$class])) {
self::addClass($class, self::$classes[$class]);
if (self::classExists($class)) {
return true;
}
}
// Datei im Cache drin, jedoch exsistiert sie nichtmehr
unset(self::$classes[$class]);
self::$isNewCache = true;
}
if (is_readable(dir::classes($classPath . '.php'))) {
self::addClass($class, dir::classes($classPath . '.php'));
}
if (self::classExists($class)) {
return true;
}
$classPath = self::$composer->findFile($class);
if (!is_null($classPath)) {
self::addClass($class, $classPath);
}
return self::classExists($class);
}
示例12: __construct
/**
* Constructor
*
* @param mixed $source
* @param array $params
*/
public function __construct($source, $params = array())
{
$this->source = $this->result = is_a($source, 'Media') ? $source : new Media($source);
$this->options = array_merge(static::$defaults, $this->params($params));
$this->destination = $this->destination();
// don't create the thumbnail if it's not necessary
if ($this->isObsolete()) {
return;
}
// don't create the thumbnail if it exists
if (!$this->isThere()) {
// try to create the thumb folder if it is not there yet
dir::make(dirname($this->destination->root));
// check for a valid image
if (!$this->source->exists() || $this->source->type() != 'image') {
throw new Error('The given image is invalid', static::ERROR_INVALID_IMAGE);
}
// check for a valid driver
if (!array_key_exists($this->options['driver'], static::$drivers)) {
throw new Error('Invalid thumbnail driver', static::ERROR_INVALID_DRIVER);
}
// create the thumbnail
$this->create();
// check if creating the thumbnail failed
if (!file_exists($this->destination->root)) {
return;
}
}
// create the result object
$this->result = new Media($this->destination->root, $this->destination->url);
}
示例13: _reset
private function _reset()
{
$db = Database::instance();
// Drop all tables
foreach ($db->list_tables() as $table) {
$db->query("DROP TABLE IF EXISTS `{$table}`");
}
// Clean out data
dir::unlink(VARPATH . "uploads");
dir::unlink(VARPATH . "albums");
dir::unlink(VARPATH . "resizes");
dir::unlink(VARPATH . "thumbs");
dir::unlink(VARPATH . "modules");
dir::unlink(VARPATH . "tmp");
$db->clear_cache();
module::$modules = array();
module::$active = array();
// Use a known random seed so that subsequent packaging runs will reuse the same random
// numbers, keeping our install.sql file more stable.
srand(0);
gallery_installer::install(true);
module::load_modules();
foreach (array("user", "comment", "organize", "info", "rss", "search", "slideshow", "tag") as $module_name) {
module::install($module_name);
module::activate($module_name);
}
}
示例14: save
public static function save()
{
if (!self::$isChange) {
return true;
}
$newEntrys = array_merge(self::$params, self::$newEntrys);
return file_put_contents(dir::backend('lib' . DIRECTORY_SEPARATOR . 'config.json'), json_encode($newEntrys, JSON_PRETTY_PRINT));
}
示例15: getConfig
public static function getConfig($name)
{
$configFile = dir::addon($name, 'config.json');
if (file_exists($configFile)) {
return json_decode(file_get_contents($configFile), true);
}
return false;
}