
Following my post about Studio by WordPress.com, I’m still using XAMPP for a few projects.
By default, XAMPP offers a dashboard page at http://localhost/dashboard/ which besides some welcome blurb includes a few useful links such as to phpMyAdmin (for managing the MariaDB database).
Something I’ve often wished that it had was a way to detect the folders within htdocs and offer links to them. So, I’ve written my own.
You can find the code on my GitHub.
Code
Here’s the code:
<div class="row">
<div class="large-12 columns">
<h3>Projects</h3>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<?php
// Get the directory one level up
$parent_dir = dirname(__DIR__);
// Scan the parent directory for directories
$dirs = scandir($parent_dir);
// Filter out '.' and '..', keep only directories, and exclude 'dashboard', 'webalizer', and 'xampp'
$filtered_dirs = array_filter($dirs, function ($dir) use ($parent_dir) {
return $dir !== '.' && $dir !== '..' && is_dir($parent_dir . '/' . $dir) &&
$dir !== 'dashboard' && $dir !== 'webalizer' && $dir !== 'xampp';
});
// Output the directory names in an unordered list with links
echo '<ul>';
foreach ($filtered_dirs as $dir) {
echo '<li><a href="../' . $dir . '/">' . $dir . '</a></li>';
}
echo '</ul>';
?>
</div>
</div>
What it does
What it does is scans the parent directory for other directories, filters out the default XAMPP folder names (dashboard, webalizer and xampp), then outputs the directories with links to an unordered list.
How to use it
- Navigate to
xampp/dashboard/. - Change
index.htmltoindex.php. - Insert the code before the Community H3 heading row div.
- Er… that’s it!
- Enjoy!