Forum Moderators: coopster
// Executable from **anywhere**
$dir = 'myfolder';
$files = scandir("$_SERVER[DOCUMENT_ROOT]/$dir");
echo "<ul>";
foreach ($files as $file) {
if ($file!='.' && $file!='..' ) {
// Or . . match on the extensions you want, more common
echo "<li>$dir/$file</li>";
}
}
echo "</ul>";
function ScanDirectory($DirList){
$DirRead = array();
$DirReadList = opendir($DirList);
//read specified directory & an store instances in array
while($DirGot = readdir($DirReadList)){
if(($DirGot != ".") && ($DirGot != "..")){
$DirRead[] = $DirGot;
}
}
return count($DirRead);
}
echo ScanDirectory("a_directory_to_scan/");
function ScanCountList($dir){
$files = scandir($dir);
$counter = array();
$first = "<ul>";
foreach ($files as $file) {
if ($file!='.' && $file!='..' ) {
$counter[] = $file;
// Or . . match on the extensions you want, more common
$first .= "<li>$dir/$file</li>";
}
}
$first .= "</ul>";
return array($first,count($counter));
}
$Listings = ScanCountList('Your/path/to/directory/');
echo "File listing:-";
echo "<br>";
echo $Listings['0'];
echo "<br>";
echo "There are ".$Listings['1']." File".(($Listings['1'] > 1) ? '(s)':'')." in the Directory you specified";
$dir = 'myfolder';
$files = scandir("$_SERVER[DOCUMENT_ROOT]/$dir");
echo "<ol>";
foreach ($files as $file) {
if (preg_match('/\.jpe*g$/i',$file)) {
echo "<li>$dir/$file</li>";
}
}
echo "</ol>";
$dir = 'myfolder';
$files = scandir("$_SERVER[DOCUMENT_ROOT]/$dir");
echo "<ul>";
$count = count($files);
for ($i=0;$i<$count;$i++) {
$num=$i+1;
if (preg_match('/\.jpe*g$/i',$file)) {
echo "<li>$num $dir/$file</li>";
}
}
echo "</ul>";
function ScanCountList($dir){
$files = scandir($dir);
$counter = array();
$first = "<ol>";
foreach ($files as $file) {
if ($file!='.' && $file!='..' ) {
$counter[] = $file;
// Or . . match on the extensions you want, more common
$first .= "<li>$file</li>";
}
}
$first .= "</ol>";
return array($first,count($counter));
}
$Listings = ScanCountList('Your/path/to/directory/');
echo "File listing:-";
echo "<br>";
echo $Listings['0'];
echo "<br>";
echo "There are ".$Listings['1']." File".(($Listings['1'] > 1) ? '(s)':'')." in the Directory you specified";
$dir = 'myfolder/';
$files = scandir("$dir");
$num = 0;
$file_list=null;
foreach ($files as $file) {
if (preg_match('/\.jpe*g$/i',$file)) {
$num++;
$file_list .= "<li>$num $dir/$file</li>";
}
}
if ($file_list) { $file_list = "<ol>$file_list</ol>"; }
$root = $_SERVER['DOCUMENT_ROOT'];
$dir = 'myfolder/';
$files = scandir("$dir");
$num = 0;
$file_list=null;
foreach ($files as $file) {
if (is_file("$root/$dir/$file")) {
$num++;
$file_list .= "<li>$num $dir/$file</li>";
}
}
if ($file_list) { $file_list = "<ol>$file_list</ol>"; }
document_root may or may not have a trailing slash. So, make sure there isn't one at all to keep your code portable.