Php Laravel Input::文件返回空数组,而$\u文件有数据

Php Laravel Input::文件返回空数组,而$\u文件有数据,php,laravel,file-upload,laravel-4,Php,Laravel,File Upload,Laravel 4,为了简单起见,我认为: {{ Form::open(['route' => 'files', 'method' => 'POST', 'files' => 'true']) }} {{ Form::file('file') }} {{ Form::submit(); }} {{ Form::close() }} 在我的控制器中: return Response::json([$_FILES, print_r(Input::file('file'),1)]); 这是我提交时得

为了简单起见,我认为:

{{ Form::open(['route' => 'files', 'method' => 'POST', 'files' => 'true']) }}
{{ Form::file('file') }}
{{ Form::submit(); }}
{{ Form::close() }}
在我的控制器中:

return Response::json([$_FILES, print_r(Input::file('file'),1)]);
这是我提交时得到的回复:

[
    {
        "file": {
            "name": "sample.jpg",
            "type": "image/jpeg",
            "tmp_name": "/tmp/phpItZT7K",
            "error": 0,
            "size": 17645
        }
    },
    {}
]

我在搜索时遇到的唯一真正的解决方案是enctype,它通过form::open中的“files”属性出现在我的表单上。在这一点上,我不知道发生了什么。它并没有破坏应用程序,但仍然很烦人。如果有人能解释一下,我会很高兴的。

你还没有弄清楚实际的问题是什么,但我猜是
Input::file()
没有通过JSON。这是因为
Input::file()
返回一个无法编码的数组,因此必须创建自己的数组

$file = Input::file('file');
$output = ['name' => $file->getClientOriginalName(), 'size' => $file->getClientSize()]; // etc

您面临的问题是什么…?Input::file()没有返回任何数据。没有上载的文件对象或任何东西。从那时起,它神奇地开始在刷新之间再次工作,而我没有更改任何相关的代码,或者我相信是这样。我们也遇到了同样的问题$_FILES显示带有文件的数组,但Input::file('file')没有显示任何内容。我正在使用print_r(Input::file('file'),1)在JSON输出中打印,它始终为空。我只是忘了在帖子中包含它。试着使用Log类来记录对象,看看会发生什么。您实际上是在单击按钮还是在使用AJAX?