Check out my twitter script by CMXads
Goth and Gore Gifts Shop right now or else! | Evil gear Christmas is almost here | Viking gear Gear Gifts and Apparel | Sharp Stuff Switchblades Icepicks and german knives |
here are some of the best and useful php scripts and snippets to help in your projects. Php displayed below. Use the search for specific script lookups. Click the category links to view scripts in Javascript and cgi. To add your own script click the link and add your useful script example.
read directory and subdirectory tree list contents levels in ul and li list
read directory subdirectory tree list files
read_directory_tree Date added Jan 2012
<?php
// show directory content
function showDir($dir, $i, $maxDepth){
$i++;
if($checkDir = opendir($dir)){
$cDir = 0;
$cFile = 0;
// check all files in $dir, add to array listDir or listFile
while($file = readdir($checkDir)){
if($file != "." && $file != ".."){
if(is_dir($dir . "/" . $file)){
$listDir[$cDir] = $file;
$cDir++;
}
else{
$listFile[$cFile] = $file;
$cFile++;
}
}
}
// show directories
if(count($listDir) > 0){
sort($listDir);
for($j = 0; $j < count($listDir); $j++){
echo "
<tr>";
$spacer = "";
for($l = 0; $l < $i; $l++) $spacer .= " ";
// create link
$link = "<a href=\"" . $_SERVER["PHP_SELF"] . "?dir=" . $dir . "/" . $listDir[$j] . "\">$listDir[$j]</a>";
echo "<td>" . $spacer . $link . "</td>
</tr>";
// list all subdirectories up to maxDepth
if($i < $maxDepth) showDir($dir . "/" . $listDir[$j], $i, $maxDepth);
}
}
// show files
if(count($listFile) > 0){
sort($listFile);
for($k = 0; $k < count($listFile); $k++){
$spacer = "";
for($l = 0; $l < $i; $l++) $spacer .= " ";
echo "
<tr>
<td>" . $spacer . $listFile[$k] . "</td>
</tr>";
}
}
closedir($checkDir);
}
}
if($_GET["dir"] == "" || !is_dir($_GET["dir"])) $dir = getcwd();
else $dir = $_GET["dir"];
// replace backslashes, not necessary, but better to look at
$dir = str_replace("\\", "/", $dir);
// show parent path
$pDir = pathinfo($dir);
$parentDir = $pDir["dirname"];
echo "<a href=\"" . $_SERVER["PHP_SELF"] . "\"><h3>Home</h3></a>";
echo "Current directory: " . $dir;
echo "<a href=\"" . $_SERVER["PHP_SELF"] . "?dir=$parentDir\"><h4>Parent directory: $parentDir</h4></a>";
// Display directory content
echo"<table border=1 cellspacing=0 cellpadding=2>
<tr><th align=left>File / Dir</th>";
// specifies the maxDepth of included subdirectories
// set maxDepth to 0 if u want to display the current directory
$maxDepth = 0;
showDir($dir, -1, $maxDepth);
?>