简体   繁体   English

如何获取正在上传的文件的完整路径?

[英]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. $_FILES['file_to_upload']['name']不会返回客户端计算机上图像的完整路径。 Thus I am unable to check the type of image. 因此我无法检查图像的类型。

Try using $_FILES['file_to_upload']['tmp_name'] . 尝试使用$_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. exif_imagetype()读取图像文件的前几个字节,因此需要知道图像文件的路径,该文件存储在tmp_name字段中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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