php-pathinfo

Using pathinfo Function to Detect File Extention

Sometimes that’s not necessary to check a file’s mime type and you only need to check the file extension. To do that we can use PHP’s pathinfo() function. The function below is a an example of how to use pathinfo to parse out if a file is a PDF returning true if it is, false otherwise.

function isPDF($filePath){
	$fileParts = pathinfo($filePath);
	if($fileParts['extension']=='pdf'){
		return true;
	}
	return false;
}

Leave a Reply

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