Directory Listing - Php

How to do directory listing using php code?

Snippet Code


  
Rate this page :
  [ 0 votes]

Here, "directory_list()" function is used to list files and folders under given directory. This php code helps to display the total number of files inside the given directory.

<?php $dir = './test'; directory_list($dir); function directory_list($dir) { $files1 = scandir($dir); echo "<ul>"; foreach($files1 as $fname) { if($fname!="." amp&$fname!="..") { if(is_dir("$dir/$fname")) { $flink="$dir/$fname"; $tcount = scandir($flink); $num_files = count($tcount); $num_files =$num_files-2; echo "<li>$fname ampnbsp;ampnbsp; <span style='color:#dadada'>Directory (Total Files:$num_files)</span></li>"; } else echo "<li>$fname</li>"; } } echo "</ul>"; } ?>

Tags


Ask Questions

Ask Question