本文整理汇总了PHP中directory_to_array函数的典型用法代码示例。如果您正苦于以下问题:PHP directory_to_array函数的具体用法?PHP directory_to_array怎么用?PHP directory_to_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了directory_to_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: directory_to_array
function directory_to_array($directory, $extension = "", $full_path = true)
{
$array_items = array();
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($directory . "/" . $file)) {
$array_items = array_merge($array_items, directory_to_array($directory . "/" . $file, $extension, $full_path));
} else {
$file_ext = substr(strrchr($file, "."), 1);
if (!$extension || in_array($file_ext, $extension)) {
if ($full_path) {
$array_items[] = $directory . "/" . $file;
} else {
$array_items[] = $file;
}
}
}
}
}
closedir($handle);
} else {
die(TEXT_FAILED_OPEN_DIR . $directory);
}
return $array_items;
}
示例2: directory_to_array
function directory_to_array($directory, $ignores = NULL, $only_binary_files = false)
{
if (!$ignores) {
$ignores = array('.', '..');
}
$array_items = array();
$handle = @opendir($directory);
if (!$handle) {
return array();
}
$file = readdir($handle);
$dirs = array();
while ($file !== false) {
if (in_array($file, $ignores)) {
$file = readdir($handle);
continue;
}
$filepath = realpath($directory . "/" . $file);
$dir = array_pop(explode("/", $directory));
if (!is_readable($filepath)) {
$file = readdir($handle);
continue;
}
if (is_dir($filepath)) {
array_push($dirs, $filepath);
} else {
if ($only_binary_files && !is_binary($filepath)) {
$file = readdir($handle);
continue;
}
$relative_path = $dir != '' ? $dir . "/" : '';
$array_items[] = preg_replace("/\\/\\//si", "/", $relative_path . $file);
}
$file = readdir($handle);
}
sort($array_items);
sort($dirs);
foreach ($dirs as $filepath) {
$files = directory_to_array($filepath, $ignores, $only_binary_files);
if ($dir != '') {
array_walk($files, 'add_prefix', $dir);
}
$array_items = array_merge($array_items, $files);
}
closedir($handle);
return $array_items;
}
示例3: directory_to_array
function directory_to_array($directory, $extension = "", $full_path = true)
{
$array_items = array();
if (!($contents = scandir($directory))) {
return $array_items;
}
foreach ($contents as $file) {
if ($file != "." && $file != "..") {
if (is_dir($directory . "/" . $file)) {
$array_items = array_merge($array_items, directory_to_array($directory . "/" . $file, $extension, $full_path));
} else {
$file_ext = substr(strrchr($file, "."), 1);
if (!$extension || in_array($file_ext, $extension)) {
$array_items[] = $full_path ? $directory . "/" . $file : $file;
}
}
}
}
return $array_items;
}
示例4: get_available_models
public function get_available_models()
{
$CI =& get_instance();
$CI->load->helper('directory');
$CI->load->helper('file');
$all_models = array();
$exclude = array('index.html');
$models = directory_to_array(APPPATH . 'models/', TRUE, $exclude, FALSE, TRUE);
$all_models['application'] = array_combine($models, $models);
// loop through allowed modules and get models
$modules_allowed = $CI->config->item('modules_allowed', 'fuel');
foreach ($modules_allowed as $module) {
$module_path = MODULES_PATH . $module . '/models/';
if (file_exists($module_path)) {
$models = directory_to_array($module_path, TRUE, $exclude, FALSE, TRUE);
$all_models[$module] = array_combine($models, $models);
}
}
return $all_models;
}
示例5: tests
/**
* Returns whether documenation exists for the advanced module
*
* @access public
* @return boolean
*/
public function tests()
{
$dir_path = $this->server_path() . 'tests/';
$tests = array();
// if a directory, grab all the tests in it
if (is_dir($dir_path)) {
$tests = directory_to_array($dir_path);
}
return $tests;
}
示例6: um_component_directory_get_all_files
function um_component_directory_get_all_files($component, $binary = false)
{
if (!$component || !isset($component->path)) {
return array();
}
if (!is_dir($component->path)) {
return array();
}
$path = $component->path;
if (substr($path, -1) != '/') {
$path .= "/";
}
$files = directory_to_array($path, array('.svn', '.cvs', '.git', '.', '..'), $binary);
$blacklisted = um_component_get_all_blacklisted($component);
return array_diff($files, $blacklisted);
}
示例7: DBSavePost
function DBSavePost($post_id, $pinned, $boardName, $title, $content, $user_id, $added_tags, $deleted_tags)
{
$date = getTime();
global $db;
$stmt = $db->stmt_init();
if ($stmt->prepare('CALL Check_Post_Owner(?,?)')) {
$stmt->bind_param('ii', $post_id, $user_id);
$stmt->execute();
$stmt->bind_result($result);
$stmt->fetch();
$stmt->close();
if ($result == 0 || $post_id == -1) {
$db->next_result();
$stmt = $db->stmt_init();
//htmlspecialchars($title, ENT_HTML401, 'UTF-8', false)
if ($stmt->prepare('CALL Save_Post(?,?,?,?,?,?,?,?)')) {
$stmt->bind_param('isiissii', $post_id, $boardName, $user_id, $pinned, $title, $content, $date, $date);
$stmt->execute();
$post_id_out = NULL;
$stmt->bind_result($post_id_out);
$stmt->fetch();
$stmt->close();
if ($added_tags != null) {
for ($t = 0; $t < sizeof($added_tags); $t++) {
DBSavePostTag($post_id_out, $added_tags[$t], "Save");
}
}
if ($deleted_tags != null) {
for ($t = 0; $t < sizeof($deleted_tags); $t++) {
DBSavePostTag($post_id_out, $deleted_tags[$t], "Delete");
}
}
if ($post_id_out > 0) {
$encoded_post_id = str_replace("/", "SLASH", fnEncrypt("p" . $post_id_out));
$user_dir = "../tmp/" . $user_id . "/";
$target_dir = "../upload/" . $encoded_post_id . "/";
$files = directory_to_array($user_dir);
// if there are more than 0 files in the ../tmp/[UserID] directory
if (sizeof($files) > 0) {
// if ../upload/[UserID] direcoty does not exists, create the directory
if (!(file_exists($target_dir) && is_dir($target_dir))) {
@mkdir($target_dir, 0777, true);
} else {
//delete all files
}
$index = 0;
while ($file = $files[$index++]) {
$filesize = filesize($file);
$filealias = end(explode("/", $file));
$fileextension = end(explode(".", $filealias));
$filename = substr($filealias, 14);
$fileDirectory = $target_dir . $filename;
$fileAddress = publicUrl . "/upload/" . $encoded_post_id . "/" . $filename;
//DB Save
//$result = DBSaveUploadFile($fileextension, $post_id_out, -1, $filesize, $fileDirectory, $fileAddress);
//Check Image is in the DOM
$doc = new DOMDocument();
@$doc->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'));
$tags = $doc->getElementsByTagName('img');
foreach ($tags as $tag) {
$source = $tag->getAttribute('src');
if ($source == $user_dir . $filealias) {
$tag->removeAttribute('src');
$tag->setAttribute('src', $fileDirectory);
}
}
$newContent = @$doc->saveHTML('body');
$newContent = str_replace('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">', '', $newContent);
$db->next_result();
$stmt = $db->stmt_init();
//htmlspecialchars($title, ENT_HTML401, 'UTF-8', false)
if ($stmt->prepare('CALL Save_Post(?,?,?,?,?,?,?,?)')) {
$stmt->bind_param('isiissii', $post_id, $boardName, $user_id, $pinned, $title, $newContent, $date, $date);
$stmt->execute();
$post_id_out = NULL;
$stmt->bind_result($post_id_out);
$stmt->fetch();
$stmt->close();
}
//Move file from /tmp/ to /upload/
rename($file, $user_dir . $filename);
copy($user_dir . $filename, $target_dir . $filename);
unlink($user_dir . $filename);
}
}
}
return $post_id_out;
}
}
}
return -1;
}
示例8: dir_files
/**
* Returns a list of file types that are allowed for a particular folder
*
* @access public
* @param string folder name
* @param boolean will recursively look inside nested folders. Default is FALSE
* @param boolean will include the server path. Default is FALSE
* @return mixed
*/
public function dir_files($folder, $recursive = FALSE, $append_path = FALSE)
{
$dir = assets_server_path($folder);
return directory_to_array($dir, $recursive, array(), $append_path);
}
示例9: initialize
/**
* Initialize the user preferences
*
* Accepts an associative array as input, containing display preferences
*
* @access public
* @param array config preferences
* @return void
*/
public function initialize($config = array())
{
// setup any intialized variables
foreach ($config as $key => $val) {
if (isset($this->{$key})) {
$this->{$key} = $val;
}
}
// grab layouts from the directory if layouts auto is true in the fuel_layouts config
$this->CI->load->helper('file');
$this->CI->load->helper('directory');
$layout_path = APPPATH . 'views/' . $this->layouts_folder;
$layouts = get_filenames($layout_path);
$layout_files = directory_to_array($layout_path, TRUE);
if (!empty($layout_files)) {
foreach ($layout_files as $file) {
$layout = end(explode('/', $file));
$layout = substr($layout, 0, -4);
$file_dir = ltrim(dirname($file), '/');
if ($file_dir != ltrim($layout_path, '/')) {
$group = end(explode('/', $file_dir));
} else {
$group = '';
}
// we won't show those that have underscores in front of them'
if (substr($group, 0, 1) != '_') {
if (empty($this->layouts[$layout]) and substr($layout, 0, 1) != '_') {
$this->layouts[$layout] = array('class' => 'Fuel_layout', 'group' => $group);
} else {
if (!empty($this->layouts[$layout])) {
if (!is_object($this->layouts[$layout]) and empty($this->layouts[$layout]['group'])) {
$this->layouts[$layout]['group'] = $group;
}
}
}
}
}
}
// grab layouts from advanced module
$advanced_modules = $this->CI->fuel->modules->advanced(FALSE);
foreach ($advanced_modules as $mod) {
$path = $mod->path() . 'config/' . $mod->name() . '_layouts.php';
if (file_exists($path)) {
include $path;
if (!empty($config['layouts'])) {
$this->layouts = array_merge($this->layouts, $config['layouts']);
}
if (!empty($config['blocks'])) {
$this->blocks = array_merge($this->blocks, $config['blocks']);
}
} elseif (method_exists($mod, 'setup_layouts')) {
$mod->setup_layouts();
}
}
// initialize layout objects
foreach ($this->layouts as $name => $init) {
$this->add($name, $init);
}
}
示例10: _delete
/**
* Deletes an asset and will perform any necessary folder cleanup
*
* @access protected
* @param string An asset file to delete
* @return string
*/
protected function _delete($file)
{
$CI =& get_instance();
$file = $this->get_file($file);
$deleted = FALSE;
// cleanup beginning slashes
$doc_root = preg_replace("!{$_SERVER['SCRIPT_NAME']}\$!", '', $_SERVER['SCRIPT_FILENAME']);
$filepath = $doc_root . $file;
// normalize file path
$parent_folder = dirname($filepath) . '/';
if (file_exists($filepath)) {
$deleted = unlink($filepath);
}
$max_depth = 5;
$i = 0;
$end = FALSE;
while (!$end) {
// if it is the last file in a subfolder (not one of the main asset folders), then we recursively remove the folder to clean things up
$excluded_asset_folders = $CI->fuel->assets->excluded_asset_server_folders();
if (!in_array($parent_folder, $excluded_asset_folders)) {
$dir_files = directory_to_array($parent_folder);
// if empty, now remove
if (empty($dir_files)) {
@rmdir($parent_folder);
} else {
$end = TRUE;
}
} else {
$end = TRUE;
}
$parent_folder = dirname($parent_folder) . '/';
}
$i++;
if ($max_depth == $i) {
$end = TRUE;
}
return $deleted;
}
示例11: insert_all_directory_in_course_table
/**
* Insert into the DB of the course all the directories
* @param string path of the /work directory of the course
* @return -1 on error, sql query result on success
* @author Julio Montoya
* @version April 2008
* @param string $base_work_dir
*/
function insert_all_directory_in_course_table($base_work_dir)
{
$dir_to_array = directory_to_array($base_work_dir, true);
$only_dir = array();
for ($i = 0; $i < count($dir_to_array); $i++) {
$only_dir[] = substr($dir_to_array[$i], strlen($base_work_dir), strlen($dir_to_array[$i]));
}
$course_id = api_get_course_int_id();
$group_id = api_get_group_id();
$work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
for ($i = 0; $i < count($only_dir); $i++) {
$url = $only_dir[$i];
$params = ['c_id' => $course_id, 'url' => $url, 'title' => '', 'description' => '', 'author' => '', 'active' => '1', 'accepted' => '1', 'filetype' => 'folder', 'post_group_id' => $group_id];
Database::insert($work_table, $params);
}
}
示例12: _delete
/**
* Deletes an asset and will perform any necessary folder cleanup
*
* @access protected
* @param string An asset file to delete
* @return string
*/
protected function _delete($file)
{
$CI =& get_instance();
$file = $this->get_file($file);
$deleted = FALSE;
// cleanup beginning slashes
$assets_folder = WEB_ROOT . $CI->config->item('assets_path');
$file = trim(str_replace($assets_folder, '', $file), '/');
// Causes issues in some environments like GoDaddy... was originally changed for the assets to potentially be in a parent folder
// $doc_root = preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']);
// $filepath = $doc_root.$file;
// normalize file path
$filepath = $assets_folder . $file;
$parent_folder = dirname($filepath) . '/';
if (file_exists($filepath)) {
$deleted = unlink($filepath);
}
$max_depth = 5;
$i = 0;
$end = FALSE;
while (!$end) {
// if it is the last file in a subfolder (not one of the main asset folders), then we recursively remove the folder to clean things up
$excluded_asset_folders = $CI->fuel->assets->excluded_asset_server_folders();
if (!in_array($parent_folder, $excluded_asset_folders)) {
$dir_files = directory_to_array($parent_folder);
// if empty, now remove
if (empty($dir_files)) {
@rmdir($parent_folder);
} else {
$end = TRUE;
}
} else {
$end = TRUE;
}
$parent_folder = dirname($parent_folder) . '/';
}
$i++;
if ($max_depth == $i) {
$end = TRUE;
}
return $deleted;
}
示例13: _get_tests
function _get_tests($folder, $module = NULL)
{
$return = array();
if (file_exists($folder)) {
$tests = directory_to_array($folder);
foreach ($tests as $test) {
$dir = '/' . $test;
if (substr($test, -9) == '_test.php') {
$val = str_replace(EXT, '', end(explode('/', $test)));
$return[$module . ':' . $dir] = !empty($module) ? '<strong>' . $module . ':</strong> ' . humanize($val) : humanize($val);
}
}
}
return $return;
}
示例14: fnEncrypt
// $filealias = end(explode("/", $file));
// $filename = substr($filealias, 14);
// rename ($file, $user_dir.$filename);
// copy ($user_dir.$filename, $target_dir.$filename);
// unlink($user_dir.$filename);
// }
// }
// }
$post_id_out = 217;
$user_id = 52;
if ($post_id_out > 0) {
echo "hi";
$encoded_post_id = fnEncrypt("p" . $post_id_out);
$user_dir = "../tmp/" . $user_id . "/";
$target_dir = "../upload/" . $encoded_post_id . "/";
$files = directory_to_array($user_dir);
echo "hi";
// if there are more than 0 files in the ../tmp/[UserID] directory
if (sizeof($files) > 0) {
echo "hi";
// if ../upload/[UserID] direcoty does not exists, create the directory
if (!(file_exists($target_dir) && is_dir($target_dir))) {
@mkdir($target_dir, 0777, true);
} else {
//delete all files
}
$index = 0;
while ($file = $files[$index++]) {
$filesize = filesize($file);
$filealias = end(explode("/", $file));
$fileextension = end(explode(".", $filealias));
示例15: views
/**
* Returns an array of view files pages used with opt-in controller method
*
* @access public
* @param string name of view subfolder to search
* @return array
*/
public function views($subfolder = '')
{
$this->CI->load->helper('directory');
if (!empty($subfolder)) {
$subfolder = trim($subfolder, '/') . '/';
}
$views_path = APPPATH . 'views/' . $subfolder;
$view_pages = directory_to_array($views_path, TRUE, '/^_(.*)|\\.html$/', FALSE, TRUE);
sort($view_pages);
return $view_pages;
}