How to Get File Extension in PHP
In this tutorial, we will learn How to Get File Extension in PHP. We use the PHP default pathinfo() function to get the file extension of a file. the pathinfo() can give you other information, such as canonical path, depending on the constant you pass to it. PHP file extension is very useful in order to get proper validation for any upload of the files. An extension from the file name or file location is very useful. when programmers know that they must upload or manipulate files only PHP, not any other programming language or file with any other extension.
Example
<?php $file_name = "D:\xampp\htdocs\test.php"; $file_extension = pathinfo($file_name, PATHINFO_EXTENSION); echo "The file extension is : ".$file_extension; Output: The file extension is : php