Sunday 30 December 2012

How to get the Extension of a File Using PHP

This tutorial teaches you how to get the extension of any file for instance, gif from image.gif or any other file of your choice using PHP.

There are situations where you may need to get the extension of a given file for a certain purpose.

You may need to get the extension of the file in order to re-size it or you may need to check to see if an uploaded file has a particular extension so as to perform a certain task.

There are numerous ways to do this using PHP.

You can check the physical file type, you can use string position to count in from the end of the string, you can use a regular expression to find the extension, or you can use explode to split the string and then count the array and use the last value in the array as the extension.

All depends on your choice of coding operation and the security requirements. 


How to get the Extension of a File Using PHP