PHP Tool
PHP Show Folders in Directory
Show clickable folders with PHP as long as an index.php file exists inside them.
This demo shows sample results only. It does not scan the real server on this public page.
Demo Output
Showing 3 sample folders.
What It Does
- Scans one directory
- Shows folders only
- Requires
index.phpinside each folder - Ignores hidden and common system folders
- Can show the last modified date of each folder’s
index.php - Can be marked
noindexfor private use
Drop-In PHP 8.4 File
Save this as something like folders.php in your root.
<?php
declare(strict_types=1);
/*
* Drop this file into your site root.
* Shows only visible folders that contain index.php.
* PHP 8.4 compatible.
*/
header('Content-Type: text/html; charset=UTF-8');
header('X-Robots-Tag: noindex, nofollow, noarchive, nosnippet', true);
$rootPath = __DIR__;
$skipFolders = [
'cgi-bin',
'.well-known',
'vendor',
'node_modules',
'.git',
'.svn',
'__pycache__',
];
function h(string $value): string
{
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}
function isHiddenOrSkipped(string $name, array $skipFolders): bool
{
if ($name === '.' || $name === '..') {
return true;
}
if (str_starts_with($name, '.')) {
return true;
}
return in_array(strtolower($name), array_map('strtolower', $skipFolders), true);
}
$folders = [];
$items = scandir($rootPath);
if ($items !== false) {
foreach ($items as $item) {
if (isHiddenOrSkipped($item, $skipFolders)) {
continue;
}
$fullPath = $rootPath . DIRECTORY_SEPARATOR . $item;
if (!is_dir($fullPath)) {
continue;
}
$indexFile = $fullPath . DIRECTORY_SEPARATOR . 'index.php';
if (!is_file($indexFile)) {
continue;
}
$folders[] = [
'name' => $item,
'url' => '/' . rawurlencode($item) . '/',
'modified' => @filemtime($indexFile) ?: null,
];
}
}
usort(
$folders,
static fn(array $a, array $b): int => strcasecmp($a['name'], $b['name'])
);
$totalFolders = count($folders);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex,nofollow,noarchive,nosnippet">
<title>Folder Links (<?php echo $totalFolders; ?>)</title>
<style>
body{
margin:0;
background:#111;
color:#eee;
font:16px/1.5 Arial,Helvetica,sans-serif;
}
.wrap{
max-width:760px;
margin:40px auto;
padding:24px;
}
h1{
margin:0 0 18px;
font-size:24px;
}
.note{
color:#aaa;
margin:0 0 20px;
}
.count{
margin:0 0 20px;
color:#7db8ff;
font-weight:bold;
}
.list{
display:grid;
gap:10px;
}
a{
display:block;
padding:12px 14px;
background:#1b1b1b;
border:1px solid #2a2a2a;
border-radius:10px;
color:#7db8ff;
text-decoration:none;
}
a:hover{
background:#222;
border-color:#3a3a3a;
}
.row{
display:flex;
justify-content:space-between;
align-items:center;
gap:12px;
}
.folder-name{
font-weight:bold;
word-break:break-word;
}
.folder-date{
color:#aaa;
font-size:13px;
white-space:nowrap;
}
.empty{
color:#aaa;
padding:12px 14px;
background:#1b1b1b;
border:1px solid #2a2a2a;
border-radius:10px;
}
@media (max-width:600px){
.row{
display:block;
}
.folder-date{
display:block;
margin-top:4px;
white-space:normal;
}
}
</style>
</head>
<body>
<div class="wrap">
<h1>Folders with index.php</h1>
<p class="note">Only visible folders containing an <code>index.php</code> file are shown. Date shown is the last modified date of that file.</p>
<p class="count">Showing <?php echo $totalFolders; ?> folder<?php echo $totalFolders === 1 ? '' : 's'; ?></p>
<div class="list">
<?php if (!empty($folders)): ?>
<?php foreach ($folders as $folder): ?>
<a href="<?php echo h($folder['url']); ?>">
<span class="row">
<span class="folder-name"><?php echo h($folder['name']); ?>/</span>
<span class="folder-date">
<?php if ($folder['modified']): ?>
Updated <?php echo date('M j, Y g:i A', $folder['modified']); ?>
<?php else: ?>
Date unavailable
<?php endif; ?>
</span>
</span>
</a>
<?php endforeach; ?>
<?php else: ?>
<div class="empty">No matching folders found.</div>
<?php endif; ?>
</div>
</div>
</body>
</html>
robots.txt Example
User-agent: * Disallow: /folders.php
Notes
For a real install, this script should usually stay private and unindexed. The public page here is a styled example for copy-paste use.
Looking for more lightweight tools? Browse the full VibeScriptz tools collection.