为什么图像上传失败php的is_uploaded_file检查? [英] Why does image upload fail php's is_uploaded_file check?

查看:234
本文介绍了为什么图像上传失败php的is_uploaded_file检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个允许图片上传的html表单,但是上传的图片现在因为某种原因没有通过is_uploaded_file检查。

为什么上传失败is_uploaded_file检查?



HTML:

 < form enctype =multipart / form-dataid =RecipeAddFormmethod =post
action =/ recipes / addaccept-charset =utf-8>
<! - ---省略标记 - >
< input type =filename =data [Recipe] [image]value =id =RecipeImage/>
<! - ---省略标记 - >
< / form>

PHP:

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

我在$ file或$ _FILES数组上做了一个转储:

 数组

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

文件大小不是太大,错误是0。它是否会失败is_uploaded_file检查?

解决方案

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


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

So why does the upload fail the is_uploaded_file check?

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'; 

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
)

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

解决方案

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'])

这篇关于为什么图像上传失败php的is_uploaded_file检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆