简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM