Skip to main content
PHP Blog

Back to all posts

How to Display the Filename Under File In PHP?

Published on
3 min read
How to Display the Filename Under File In PHP? image

Best PHP File Display Methods to Buy in October 2025

1 Expert PHP 5 Tools

Expert PHP 5 Tools

BUY & SAVE
$54.99
Expert PHP 5 Tools
2 PHP Cookbook: Modern Code Solutions for Professional Developers

PHP Cookbook: Modern Code Solutions for Professional Developers

BUY & SAVE
$32.88 $65.99
Save 50%
PHP Cookbook: Modern Code Solutions for Professional Developers
3 PHP Hacks: Tips & Tools For Creating Dynamic Websites

PHP Hacks: Tips & Tools For Creating Dynamic Websites

  • AFFORDABLE PRICES FOR QUALITY READS, BUDGET-FRIENDLY CHOICES!
  • ECO-FRIENDLY OPTION: GIVE BOOKS A SECOND LIFE AND SAVE TREES!
  • RELIABLE CONDITION: QUALITY ASSURED FOR AN ENJOYABLE READING EXPERIENCE!
BUY & SAVE
$21.45 $29.95
Save 28%
PHP Hacks: Tips & Tools For Creating Dynamic Websites
4 PHP 8 Objects, Patterns, and Practice: Mastering OO Enhancements, Design Patterns, and Essential Development Tools

PHP 8 Objects, Patterns, and Practice: Mastering OO Enhancements, Design Patterns, and Essential Development Tools

BUY & SAVE
$59.99
PHP 8 Objects, Patterns, and Practice: Mastering OO Enhancements, Design Patterns, and Essential Development Tools
5 Kaisi Professional Electronics Opening Pry Tool Repair Kit with Metal Spudger Non-Abrasive Nylon Spudgers and Anti-Static Tweezers for Cellphone iPhone Laptops Tablets and More, 20 Piece

Kaisi Professional Electronics Opening Pry Tool Repair Kit with Metal Spudger Non-Abrasive Nylon Spudgers and Anti-Static Tweezers for Cellphone iPhone Laptops Tablets and More, 20 Piece

  • COMPREHENSIVE TOOLSET FOR ALL YOUR DEVICE REPAIR NEEDS!
  • DURABLE STAINLESS STEEL TOOLS FOR LONG-LASTING PERFORMANCE!
  • INCLUDES CLEANING TOOLS FOR A FLAWLESS FINISH EVERY TIME!
BUY & SAVE
$9.99 $11.89
Save 16%
Kaisi Professional Electronics Opening Pry Tool Repair Kit with Metal Spudger Non-Abrasive Nylon Spudgers and Anti-Static Tweezers for Cellphone iPhone Laptops Tablets and More, 20 Piece
6 PHP Development Tool Essentials

PHP Development Tool Essentials

BUY & SAVE
$24.99
PHP Development Tool Essentials
7 iFixit Jimmy - Ultimate Electronics Prying & Opening Tool

iFixit Jimmy - Ultimate Electronics Prying & Opening Tool

  • THIN STEEL BLADE REACHES TIGHT GAPS FOR SEAMLESS REPAIRS.
  • ERGONOMIC HANDLE ENABLES PRECISE CONTROL FOR ANY TASK.
  • VERSATILE TOOL FOR TECH FIXES AND HOME IMPROVEMENT PROJECTS.
BUY & SAVE
$7.95
iFixit Jimmy - Ultimate Electronics Prying & Opening Tool
8 Build a real Search Engine: Engineering tools: HTML, CSS, JavaScript, PHP, MySQL

Build a real Search Engine: Engineering tools: HTML, CSS, JavaScript, PHP, MySQL

BUY & SAVE
$19.90
Build a real Search Engine: Engineering tools: HTML, CSS, JavaScript, PHP, MySQL
+
ONE MORE?

To display the filename under a file in PHP, you can use the basename() function to extract the filename from the file path. Here's an example of how you can achieve this:

$file = '/path/to/file.txt'; $filename = basename($file);

echo "Filename: " . $filename;

In this example, we define the file path as $file and then use the basename() function to extract the filename from it. The extracted filename is stored in the variable $filename. Finally, we can display the filename using the echo statement by concatenating it with the desired text.

How to display only the filename without the parent folder using PHP?

You can use the basename() function in PHP to display only the filename without the parent folder. The basename() function returns the trailing name component of a path.

Here's an example:

$path = '/path/to/parent/folder/filename.txt'; $filename = basename($path); echo $filename; // Output: filename.txt

In the example above, the basename() function retrieves the filename from the given path and assigns it to the $filename variable. Finally, the filename is echoed to the output.

How to display the filename in uppercase letters using PHP?

To display the filename in uppercase letters using PHP, you can use the strtoupper() function. Here's an example:

$filename = "example.txt"; $uppercaseFilename = strtoupper($filename);

echo "Uppercase Filename: " . $uppercaseFilename;

Output:

Uppercase Filename: EXAMPLE.TXT

How can I display the filename using a specific format in PHP?

To display the filename using a specific format in PHP, you can use various string manipulation functions and date functions.

Here is an example that demonstrates displaying the filename with a specific format:

In this example, the filename is initially set as "example_file.txt". First, we use the pathinfo() function with the PATHINFO_FILENAME flag to remove the file extension, resulting in "example_file". Then, we format the filename by converting it to uppercase using the strtoupper() function and replacing underscores with dashes using the str_replace() function. Finally, we use the date() function to generate a timestamp in the format "Ymd_His" and prepend it to the filename.

The output of this example will be "20220223_165759_EXAMPLE-FILE", assuming the current date and time is February 23, 2022, 16:57:59. You can modify the formatting as per your specific requirements.

How do I display the filename with its modified date using PHP?

To display the filename with its modified date using PHP, you can use the filemtime() function. Here is an example code to achieve this:

Replace 'example.txt' with the actual filename you want to display. The filemtime() function retrieves the Unix timestamp of the last modification time of the file, which is then formatted using the date() function to display in a human-readable format.