/** * Recurses into a directory and writes the structure * in an associative array * @global string $pictureDir from config.php * @param string $directory The directory to recurse into * @param array $array The array to put the results in * @param int $depth How deep should it go? (Default 1) * @return array * */ function recurse_dir($directory, $array, $depth = 1, $include_info = true, $full_path = false) { // echo $directory,"<br><br>"; global $pictureDir; $dirName = basename($directory); if (!is_dir($directory)) { include '404.php'; } $gallery_info = getGalleryInfo($dirName); //get images to be ignored from gallery.json if (is_array($gallery_info["ignore"])) { $ignore_images = $gallery_info["ignore"]; } else { $ignore_images = array(); } if ($handle = opendir($directory)) { //for each entry found inside $directory while (false !== ($entry = readdir($handle))) { $path = $directory . "/" . $entry; //echo "$pictureDir -- $dirName -- $path -- $entry \n </br>"; //ignore . and .. , write directories to the array and recurse into them if ($entry != "." && $entry != ".." && !in_array($entry, $ignore_images)) { if (is_dir($path)) { $array[$entry] = array(); if ($include_info) { $array[$entry]["__info__"] = getGalleryInfo($path); } if ($depth != 0) { $array[$entry] = recurse_dir($path, $array[$entry], $depth - 1, $include_info, $full_path); } } else { if (is_image($path)) { $array[$entry] = $full_path ? $path : $entry; } } } } closedir($handle); } //echo "final"; _print_r($array); return $array; }
function recurse_dir($dir, $max_dir) { global $dir_count; $dir_count++; if ($cdir = @dir($dir)) { while ($entry = $cdir->read()) { if ($entry != '.' && $entry != '..') { if (is_dir($dir . $entry) && is_writable($dir . $entry)) { if ($dir_count > $max_dir) { return; } echo "[" . $dir_count . "] " . $dir . $entry . "\n"; recurse_dir($dir . $entry . DIRECTORY_SEPARATOR, $max_dir); } } } $cdir->close(); } }
function recurse_dir($dir, $ext, $skip) { # echo "In DIR $dir<br>"; global $movies, $doubles; if ($dh = opendir($dir)) { while ($file = readdir($dh)) { // Exclude all dot file, CVS and lost+found directories if (preg_match($skip, $file)) { continue; } // If the file is a movie, we add it to the list if (preg_match("/\\.({$ext})\$/", $file)) { if (isset($movies[$file])) { array_push($doubles, $movies[$file]); array_push($doubles, "{$dir}/{$file}"); } else { $movies[$file] = "{$dir}/{$file}"; } } else { if (is_dir("{$dir}/{$file}")) { recurse_dir("{$dir}/{$file}", $ext, $skip); } } } closedir($dh); } return false; }
/** * @return void * @param unknown * @param unknown * @desc Recurses a dir tree and execs the '$func' on all the files AND the directories. */ function recurse_dir($dir, $func, $arglist = null) { $list = lscandir($dir); if (!$list) { return; } foreach ($list as $file) { if ($file === "." || $file === "..") { continue; } $path = $dir . "/" . $file; if (lis_dir($path)) { recurse_dir($path, $func, $arglist); } /// After a successfuul recursion, you have to call the $func on the directory itself. So $func is called whether $path is both directory OR a file. $narglist[] = $path; foreach ((array) $arglist as $a) { $narglist[] = $a; } call_user_func_array($func, $narglist); } }
if (!is_dir($pictureDir . "/" . $requested_path)) { $goToImage = basename($requested_path); $requested_path = str_replace($goToImage, "", $requested_path); } $path = $pictureDir . "/" . $requested_path; $array = recurse_dir($pictureDir . "/" . $requested_path, $galleries, 1); $galleryName = basename($requested_path); // echo $requested_path; die; include 'slideshow.php'; //showcase } else { if ($requested_path_array[0] == "showcase") { $counter = 0; $requested_path = str_replace("/showcase/", "", $requested_path); $path = $pictureDir . "/" . $requested_path; $array = flatten(recurse_dir($pictureDir . "/" . $requested_path, $galleries, 100, false, true)); shuffle($array); $galleryName = basename($requested_path); // echo $requested_path; die; include 'showcase.php'; //gallery } else { $galleryInfo = getGalleryInfo($pictureDir . "/" . $requested_path); $galleryName = "- " . $galleryInfo["name"]; $array = recurse_dir($pictureDir . "/" . $requested_path, $galleries, 1); ksort($array); $hasImages = hasImages($array); include './gallery.php'; } } }
function recurse_dir($base_dir) { foreach (scandir($base_dir) as $filename) { $full_path = $base_dir . "/" . $filename; if (substr($full_path, -1) != ".") { if (is_dir($full_path)) { recurse_dir($base_dir . "/" . $filename); list_dir($full_path); } else { // full path is a file convert_to_html($full_path); } } } }
<?php require_once 'config.php'; require_once 'functions.php'; header("Content-type: text/javascript"); header("Access-Control-Allow-Origin: *"); $galleries = array(); if (isset($_GET['showcase'])) { $array = flatten(recurse_dir($pictureDir, $galleries, 100, false, true)); shuffle($array); echo json_encode($array); } else { echo "var list=\n" . json_encode(recurse_dir($pictureDir, $galleries, 100 * showcase, !$showcase, $showcase), JSON_PRETTY_PRINT); } //