The PHP pathinfo() function returns information about a file path.

				
					<?php
print_r(pathinfo('/files/test.txt'));
?>
				
			

Output

				
					Array
(
[dirname] => /files
[basename] => test.txt
[extension] => txt
)
				
			

Syntax

				
					pathinfo(path, options)
				
			

Parameters

ParameterDescription
pathSpecifies the path to be checked (required)
optionsSpecifies which array element to return:

  • PATHINFO_DIRNAME - return only dirname

  • PATHINFO_BASENAME - return only basename

  • PATHINFO_EXTENSION - return only extension

  • PATHINFO_FILENAME - return only filename