Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
Menlo Park desk3 min

How to List and Link PHP Files in a Folder, with a Meta Description

A practical PHP pattern for listing .php files as links, keeping filesystem paths separate from public URLs, escaping output, and adding a description to the listing page.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The 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.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.Support on Ko-Fi

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.