php directory listing

<?php
// 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
continue;
}else{
if(($f1!= ‘.’) && ($f1!= ‘..’)) {
if(!is_dir($f1)) $filecount1++;

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

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

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

<head>
<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=“https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css” rel=“stylesheet”
integrity=“sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3” crossorigin=“anonymous”>
<style>
.card {
box-shadow: 0px 3px 19px darkgrey;
}
</style>

<title>Localhost – Kanhu</title>
</head>

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

<?php
$count = 1;

foreach ($files as $f1) {

echo
<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>
</div>
</div>
</div>
</div>’;
}

?>
</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=“http://127.0.0.1/pgadmin4/” target=“_blank”
class=“btn btn-primary”>Go </a></div>
</div>
</div>
</div>

</div>
</div>
</div>
</body>

</html>

Leave a Comment

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