【发布时间】:2018-06-22 04:25:44
【问题描述】:
我正在尝试在 laravel 项目中使用 dropzone,但我无法在服务器端获取文件。
我的刀片 html 代码:
{!! Form::open(['id' => 'create-intervention-form', 'url' => '/create-intervention', 'method' => 'post', 'class' => '']) !!}
<div id="multimedia" class="data new dropzone">
</div>
<div class="btn-new-bottom">
<a href="#new-intervention">Criar Intervenção</a>
</div>
{!! Form::close() !!}
在 jquery 中我输入了这段代码:
$("div#multimedia").dropzone({
url: "/create-intervention",
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 1024,
autoProcessQueue: false
});
要提交表单,我需要提交一个 jquery 函数。在控制器中,我尝试获取 $files[] = Input::file('file'); 但这返回 null。
控制器:
public function store(Request $request)
{
$rules = array(
);
// do the validation ----------------------------------
// validate against the inputs from our form
$validator = Validator::make(Input::all(), $rules);
// check if the validator failed -----------------------
if ($validator->fails())
{
// get the error messages from the validator
$messages = $validator->messages();
return redirect()->back()->withErrors($validator)->withInput();
}
else
{
$files[] = Input::file('file');
var_dump($files);
}
};
我该怎么做?我想使用 dropzone 上传多个文件,但只是在我提交表单时。在控制器中,我必须将每个文件保存在目录中,并将文件名保存在数据库中。
谢谢
【问题讨论】:
-
您可以在控制器中发布更多代码吗?
-
@JoseRojas 我用控制器代码更新了这个问题。我只是想接收要处理的文件,但 var_dump 返回 null。
-
在您的表单上尝试添加
enctype="multipart/form-data"。 -
返回此错误:为 foreach() @WildBeard 提供的参数无效
标签: javascript php jquery laravel dropzone.js