为什么图片上传失败 php 的 is_uploaded_file 检查?

2022-01-09 00:00:00 forms upload php html

我有一个允许上传图片的 html 表单,但现在上传的图片由于某种原因未能通过is_uploaded_file"检查.

I have a html form that allows image uploads, but the image uploaded now fails the "is_uploaded_file" check for some reason.

那么为什么上传失败了 is_uploaded_file 检查?

HTML:

<form enctype="multipart/form-data" id="RecipeAddForm" method="post"
action="/recipes/add" accept-charset="utf-8">
    <!--- Omitted Markup -->
    <input type="file" name="data[Recipe][image]" value="" id="RecipeImage" />
    <!--- Omitted Markup -->
</form>

PHP:

// returns false
echo is_uploaded_file($file['tmp_name'])?'true':'false'; 

我对 $file 或 $_FILES 数组进行了转储:

I did a dump on the $file or $_FILES array:

Array
(
    [name] => add or remove.jpg
    [type] => image/jpeg
    [tmp_name] => E:\xampp\tmp\phpB9CB.tmp
    [error] => 0
    [size] => 71869
)

文件大小不是太大,错误为0,为什么is_uploaded_file检查失败?

File size is not too large, and the error was 0. So why does it fail the is_uploaded_file check?

推荐答案

可能是windows的问题,因为它区分大小写,如果路径不同则不匹配.尝试使用 realpath($file['tmp_name'])

Might be a problem with windows, since it's case sensitive and will not match if the path is different. Try using realpath($file['tmp_name'])

相关文章