How to get the file extension in PHP

To get file extension in PHP is so easy using php default function. Some programmer used string function or explode function of php. But php provide pathinfo() which returns information about path: either an associative array or a string, depending on options.

$path = $_FILES['image']['name'];
$ext = pathinfo($path, PATHINFO_EXTENSION);


Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.
Harinder Singh

Harinder Singh

My name is Harinder Singh and I specialize in Software industry. I consider myself as a life learner. I love learning new concepts, embracing new ideas and reading and searching for innovation.