PHP – Get file extension

In this tutorial, we are going to see how to get file extension in PHP. Get a file extension from a string is an important task when validating a file for an upload. For example, if you have a file upload tool that you want to use only for image uploads, you need to validate that the file extension is an image extension(.png, .jpg .gif, etc…).

How to get file extension in PHP
	function get_file_extension($file) {
		return substr(strrchr($file,'.'),1);
	echo get_file_extension('image.jpg');




mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *