//DIRECTORY-NAVIGATION-LINKS.PHP /* Do you have a website with a navigation system that follows its directory structure? If so, these functions can be just what you need. combined with my Absolute Include function, you can implement a navigation solution that requires very little maintenance.
directories() returns an array of directories: The one containing the script itself, and its parents. directory_navigation_links() calls directories() and uses the return value to create a navigation bar. */
<? function directories() { $directory = $_SERVER["PHP_SELF"];
$directories = array();
$next_slash = 0;
do {//Creates an array with all the parent folders //of the file where this function is called. $next_slash = strpos($directory, "/", $next_slash);
//Uses the directories() function to create the links. function directory_navigation_links() { $directories = directories();
$links = "";
for($index = 0; $index < count($directories); $index++) { //Handling the display is a little harder than the links themselves. $dir_name = substr($directories[$index], 0, strlen($directories[$index]) - 1);
// ABSOLUTE-INCLUDE.PHP /* A small but useful wrapper function for include(). It allows the same include statement to be used in all the files in a website, regardless of which folder they are located in. This is handy for sites that are hosted on servers that have PHP open_basedir protection enabled. This tends to cause calls like include("/folder/file.inc"); to generate error messages. */
<? function absolute_include($file) { /* $file is the file url relative to the root of your site. Yourdomain.com/folder/file.inc would be passed as "folder/file.inc" */
Har ikke PHP på denneher maskine, så jeg kan ikke teste/rode, men jeg fandt et andet script, som måske kan bruges...til et eller andet
//example showing how to "index" the directory that the script resides in. //also allows you to browse directorys within that directory. //only allows people to browse your web directory and not your whole file system
<?php /** * array getFolder(string $path[, int $sort]) * * Gets a list of files and returns them in a multidimensional array having the format * * $array['dir'][] = "directory"; * $array['file'][] = "filename"; * * $path is a string containing a valid path on the local filesystem * $sort is an integer with a value of 1 or 0, 1 sorts in descending order, 0 sorts in ascending. * $sort defaults to ascending order if omitted * **/
function getFolder($path, $sort = 0) {
// typecast our integer, to be on the safe side $sort = (int)$sort;
// check to see if there was a trailing slash. if no slash, add one if (substr($path, -1) != '/') { $path.='/'; }
// confirm that the path exists if (!file_exists($path)) { die("$path does not exist"); }
// confirm that the path is readable elseif (!is_readable($path)) { die("no permissions to view $path with this user"); }
// confirm that $path is a directory elseif(!is_dir($path)) { die("$path is not a directory"); }
$directory = array(); $hp = opendir($path);
// build a multidimensional array of files and folders while (false !== ($file = readdir($hp))) { if (($file!='..') && ($file!='.')) { if (is_dir($path.$file)) { $directory['dir'][] = $file; } elseif (is_file($path.$file)) { $directory['file'][] = $file; } } }
// IMPORRTANT NOTE: A lot of people will be tempted to use foreach() here. It's strongly // suggested that you don't unless you need to modify the array while looping over it. // The reason you shouldn't is that PHP will make a copy of the array needlessly to loop over. // each() on it's own does not have that effect.
while (list($key, $val) = each($files['dir'])) { echo "[$val]<br>"; }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.