php directory listing

// you can add to the array
$ext_array = array(“.htm”, “.php”, “.asp”, “.js” ,“.css”); //list of extensions not required
$dir1 = “.”;
$filecount1 = 0;
$d1 = dir($dir1);

while ($f1 = $d1->read()) {
$fext = substr($f1,strrpos($f1,“.”)); //gets the file extension
if (in_array($fext, $ext_array)) { //check for file extension in list
if(($f1!= ‘.’) && ($f1!= ‘..’)) {
if(!is_dir($f1)) $filecount1++;

$key = filemtime($f1);
$files[$key] = $f1 ;

// use either ksort or krsort => (reverse order)

<!DOCTYPE html>
<html lang=“en”>

<meta charset=“UTF-8”>
<meta http-equiv=“X-UA-Compatible” content=“IE=edge”>
<meta name=“viewport” content=“width=device-width, initial-scale=1.0”>
<link href=“[email protected]/dist/css/bootstrap.min.css” rel=“stylesheet”
integrity=“sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3” crossorigin=“anonymous”>
.card {
box-shadow: 0px 3px 19px darkgrey;

<title>Localhost – Kanhu</title>

<div class=“container mt-4”>
<div class=“row”>

$count = 1;

foreach ($files as $f1) {

<div class=”col-sm-4″>
<div class=”card”>
<div class=”card-body”>
<div class=”d-flex justify-content-between”>

<h5 class=”p-2″>’.$f1.‘</h5>
<div class=”ml-auto p-2″><a href=”‘.$f1.‘” target=”_blank”
class=”btn btn-primary”>Go </a></div>

<!– For Static Links–>
<div class=“row mt-4”>
<div class=“col-sm-4”>
<div class=“card”>
<div class=“card-body”>
<div class=“d-flex justify-content-between”>
<h5 class=“p-2”>pgAdmin</h5>
<div class=“ml-auto p-2”><a href=“” target=“_blank”
class=“btn btn-primary”>Go </a></div>



Leave a Comment

Your email address will not be published. Required fields are marked *