Suhail Gupta
Suhail Gupta

Reputation: 23206

How to get the complete path of the file being uploaded?

I want to check the type of image being uploaded. I wrote the following snippet for this.

if(exif_imagetype($_FILES['file_to_upload']['name']) == IMAGETYPE_JPEG) {
    echo "This is a JPEG image";
}else if(exif_imagetype($_FILES['file_to_upload']['name']) == IMAGETYPE_PNG) {
    echo "This is a png image";
}else { echo "else statement"; }

but $_FILES['file_to_upload']['name'] doesn't return the complete path of the image on the client's computer. Thus I am unable to check the type of image.

Upvotes: 0

Views: 229

Answers (1)

Martin
Martin

Reputation: 410

Try using $_FILES['file_to_upload']['tmp_name']. exif_imagetype() reads first few bytes of a image file, hence it needs to know the path to the image file, which is stored in the tmp_name field.

Upvotes: 2

Related Questions