PHP Upload only image using file upload

PHP upload only images

In this php file upload tutorial we will learn to make restriction to upload image as per our requirement.
Here, we allow only images to be uploaded using file upload in php, so we need to check extension of uploaded file, to ensure that is image or not.

Here, we take a php file upload example that allow to upload only ‘jpg’, ‘jpeg’, ‘gif’ and ‘png’ image.

For check upload file extension.

pathinfo(“image_name”, PATHINFO_EXTENSION)

PHP File upload example

Example of check extension of uploading image.

The output of php example is :

php file upload
PHP upload image type check example


We can also do same above things using $_FILES[“file”][“type”] in php.


2 thoughts on “PHP Upload only image using file upload

Leave a Reply

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