在我的laravel 5.2项目中,我需要创建一个多文件上传区域。我选择Dropzone.js 现在我的问题是如何使用这个插件与laravel。
这是我的观点:
<div class="tab-pane" id="tab_2">
<div class="box-body">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Facebook:</label>
<div class="col-sm-10">
<input type="text" name="facebook" class="form-control">
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Twitter:</label>
<div class="col-sm-10">
<input type="text" name="twitter" class="form-control">
</div>
</div>
<div class="form-group">
<label for="video" class="col-sm-2 control-label">Video:</label>
<div class="col-sm-10">
<input type="text" name="video" class="form-control">
</div>
</div>
<!--File Upload-->
<div class="dropzone" id="dropzoneFileUpload">
</div>
<script type="text/javascript">
var baseUrl = "{{ url('/') }}";
var token = "{{ Session::getToken() }}";
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("div#dropzoneFileUpload", {
url: baseUrl+"/dropzone/uploadFiles",
params: {
_token: token
}
});
Dropzone.options.myAwesomeDropzone = {
paramName: "file",
maxFilesize: 2, // MB
addRemoveLinks: true,
accept: function(file, done) {
},
};
</script>
我的控制员:
public function store(SpotFormRequest $request) {
$user = Auth::user();
$role = $user->role;
if($role === 'manager'){
$idagent = 1;
$idmanager = $user->id;
}
else{
$idagent=$user->id;
$idmanager=0;
}
$spot = new Spot(array(
'agent_id'=>$idagent,
'manager_id'=>$idmanager,
'name' => $request->get('spotname'),
'address' => $request->get('address'),
'zip' => $request->get('zip'),
'city'=>$request->get('city_id'),
'phone' => $request->get('phone'),
'mobile' => $request->get('mobile'),
));
$spot->save();
return redirect('/administrator/spot-new')->with('status', 'Your spot has been created!');
}
我需要将上传集成到控制器中。
答案 0 :(得分:2)
在Laravel项目中实施Dropzone可能有点棘手
这是一步一步tutorial我觉得非常有帮助
本教程包括: