Skip to content

Instantly share code, notes, and snippets.

@codersaiful
Created December 30, 2017 16:05
Show Gist options
  • Save codersaiful/38fb69a8d7956234a4b88b8bf02d45d1 to your computer and use it in GitHub Desktop.
Save codersaiful/38fb69a8d7956234a4b88b8bf02d45d1 to your computer and use it in GitHub Desktop.
Getting Directory Details Sultuion
<?php
/**
* Getting Details from a Directory.
* Project is coded by Saiful Islam.
*
* @author Saiful Islam <[email protected]>
* @package Saiful Script
* @link http://fb.com/codersaiful Saiful Islam Facebook Profile link.
*/
function getDirDetails($dir){
$files = scandir($dir);
echo '<ul>';
foreach($files as $key => $value){
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
$type = explode('.', $value);
$type = end($type);
$class = (is_file($path) ? 'file file_type_' . $type . ' ' . $type : 'folder');
if(!is_dir($path)) {
echo "<li class='{$class}'>$value</li>";
} else if($value != "." && $value != "..") {
echo "<li class='{$class}'>$value</li>";
getDirDetails($path);
}
}
echo '</ul>';
}
getDirDetails(str_replace('\\', '/', __DIR__) . '/my_dir/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment