Use PHP’s glob() to find files matching *.php, then render each filename as a link. Keep the server’s filesystem path separate from the URL a visitor opens, and escape both the link and its visible text with htmlspecialchars(). To describe the listing page, add a meta description inside its HTML <head>.
List PHP files and make each filename clickable
This example lists PHP files directly inside a fixed files directory and links each one using a web URL. Change $directory to the server-side directory to scan and $publicBase to the URL path that maps to it on your site.
As an Amazon Associate I earn from qualifying purchases.
<?php
$directory = __DIR__ . '/files';
$publicBase = '/files/';
$files = glob($directory . '/*.php') ?: [];
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="Browse the PHP files available in this folder.">
<title>PHP files</title>
</head>
<body>
<ul>
<?php foreach ($files as $path):
$name = basename($path);
$href = $publicBase . rawurlencode($name);
?>
<li><a href="<?= htmlspecialchars($href, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') ?>"><?= htmlspecialchars($name, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') ?></a></li>
<?php endforeach; ?>
</ul>
</body>
</html>
glob() returns matching pathnames; the pattern *.php selects PHP files in the specified directory, not files in its subdirectories. The example uses basename() for the displayed filename and builds the browser-facing URL from a separate base path. A filesystem path such as /var/www/site/files/example.php is not automatically a valid public URL.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteThe filename is URL-encoded for use in the link, and both the URL attribute and visible filename are HTML-escaped. PHP documents htmlspecialchars() as converting HTML-significant characters to entities; using a matching character set makes it suitable for most HTML-document contexts. See the PHP htmlspecialchars() documentation.
#1 Best Overall
This is an illustrative pattern, not a complete security review or a tested deployment. Keep the scanned directory fixed or strictly constrained if users can influence input; do not let user input select arbitrary server paths. Also ensure the public URL base maps only to files intended to be accessible from the web.
Choose between glob() and scandir()
| Function | What it returns | When it fits |
|---|---|---|
glob() |
Pathnames matching a pattern, such as *.php. |
Use it when you want a concise match for one filename pattern. |
scandir() |
Files and directories in the specified directory; entries are sorted ascending alphabetically by default. | Use it when you need to inspect all entries, apply your own filter, or control ordering. |
For the second approach, call scandir() on the fixed directory, then filter the returned names for the extension you want before generating links. It includes directory entries as well as files, so filtering is important. Refer to the PHP glob() documentation and PHP scandir() documentation.
Rank #2
Put the meta description on the listing page
The <meta name="description"> in the example describes the generated listing page. Replace its content with a concise, accurate summary of what that particular page offers; if you create multiple listing pages, make each description specific to its page.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →A meta description can help Google produce a useful search snippet, but it does not control the snippet reliably. Google says snippets are primarily created from page content and may use a meta description when it better describes the page. It can also truncate snippets to fit the display, with no universal fixed character limit promised. See Google Search Central’s guidance on snippets and meta descriptions.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.If you mean extracting descriptions from the listed files
That is different from describing the directory listing itself. PHP’s get_meta_tags() reads a file and parses meta-tag content attributes from its text; it does not create links or supply metadata automatically. See the PHP get_meta_tags() documentation.
A .php file may generate HTML dynamically, so parsing its raw source does not necessarily reveal the metadata visitors or search engines receive in the rendered response. Use this approach only when the files contain parseable meta tags in the file content. If you need the final description users see, inspect the generated HTML response instead.
Quick Recap
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




