$files = scandir($folderName);
if($files){
$totalfiles = count($files);
if ( $totalfiles == 2 ) { //read http://php.net/manual/en/function.scandir.php to see why I checked for 2
echo "This folder is empty.";
exit();
}
$looper = 0;
while( $totalfiles > $looper ){
if( $looper != 0 && $looper != 1 && !is_dir($folderName."/".$files[$looper]) ){ // for files inside the folder
echo $files[$looper];
echo "<a href='".$folderName."/".$files[$looper]."'>Download file</a>"; // a simple way to make the file downloadable ;)
}
if( $looper != 0 && $looper != 1 && is_dir($folderName."/".$files[$looper]) ){ // for folder inside the folder
echo $files[$looper]; // echos folder's name
echo "<a href='".$folderName."/".$files[$looper]."'>Open Folder</a>";
//to access files inside folder's folders, repeat the process again by giving the
//$folderName with folder's folders' name
}
$looper++;
}
}else{
echo "Error while accessing the folder!!!";
}
Hope you get the idea to use this :)
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.