I have a Form field for an Image upload, which I open with 'files' => true, like so:

{{ Form::label('image', 'Image') }}
{{ Form::file('image') }}

在我的控制器中,我想判断是否上传了文件,并对其进行处理:

if (Input::hasFile('image')){
        $in_path = 'img/';
        $in_extension = Input::file('image')->getClientOriginalExtension();
        $filename = Input::get('name').".".$in_extension;
        Input::file('image')->move($in_path, $filename);
        $user->image = $filename;
    }

但是Input::hasFile总是返回错误,我不知道为什么.

Input::file('image');

结果如下:

Symfony\Component\HttpFoundation\File\UploadedFile Object
(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => test.JPG
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => application/octet-stream
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 1
[pathName:SplFileInfo:private] => 
[fileName:SplFileInfo:private] => 
)

I have tested around with another picture for another User and this works fine. I don't get why this is working for some Users and for some others not.

这个问题的原因还有哪些?

推荐答案

I solved what was wrong. The code is fine, but the problem was some pictures were simply to big.

EDIT:
As Don't Panic pointed out, editing upload_max_filesize can solve the problem.

Laravel相关问答推荐

无法在终端cPanel中打开输入文件:artisan

发送邮箱后,Laravel重定向偶尔会导致错误500

vagrant会损坏你的电脑. | macOS v12(蒙特雷)#13132

未找到 apiResource 404 中的变量

阻止用户查看其他用户正在查看的内容的最佳方法是什么?

处理程序类中的错误 - Laravel

Laravel belongsTo 关系 - 试图获取非对象的属性

Laravel 5.4 中的自定义助手类

判断 Laravel 模型表中是否存在列,然后应用条件

如何修复无效请求(不支持的 SSL 请求)

致命错误:找不到类App\Http\Controllers\Redirect

SQLSTATE [42000]:语法错误或访问冲突:1066 Not unique table/alias on relationship

使用数据库中的值进行动态邮件配置 [Laravel]

Laravel 说 Auth guard [] 没有定义

Laravel 5.4 有时验证规则不起作用

Laravel 4 验证唯一(数据库)忽略当前

如何在 Laravel 5 中验证 RESTful API?

Laravel 更新后用户模型错误(用户类包含 3 个抽象方法)

没有Access-Control-Allow-Origin标头 - Laravel

count() 参数必须是数组或在 laravel 中实现可数的对象