我想在我的网站上使用Laravel 4.2合并'Dropzone',我在他们的官方网站here中找到了一个例子。
但是当我将它添加到我的表单时,表单会改变行为,我无法处理控制器中的图像。你能用Laravel 4.2给我一个dropzone的基本例子吗?
答案 0 :(得分:2)
<script>
var myDropzone = new Dropzone("div#dropzone", {
url: "{{URL::route('compose-attachment')}}",
//clickable: "#yourSubmitButton",
paramName: "file",
addRemoveLinks: true,
init: function() {
});
});
}
});
</script>
路线:
Route::post('/compose-attachment', array( 'as' => 'postMsgAttachment','uses' => 'UserController@getPostAttachment'));
控制器:
public function getPostAttachment(){
$file = Input::file('file');
$destinationPath = public_path().'/uploads';
$time = time();
$filename = $time."-".$file->getClientOriginalName();
$upload_success = Input::file('file')->move($destinationPath, $filename);
}
答案 1 :(得分:0)
这是我的查看代码:
{{ Form::open(array('files'=> true , 'method' => 'post' ,'route' => array('article.create', Route::current()->getParameter('lang')))) }}
<div class="fallback" id = "dropzone" >
<input name="file" type="file" multiple />
</div>
{{ Form::submit(Lang::get('messages.create') , array('class' => 'btn btn-default custom-submit')) }}
{{ Form::close() }}
<script>
var myDropzone = new Dropzone("div#dropzone", {
url: "{{URL::route('compose-attachment')}}",
//clickable: "#yourSubmitButton",
paramName: "file",
addRemoveLinks: true,
init: function() {
});
});
}
});
</script>
路线:
Route::post('/compose-attachment', array( 'as' => 'postMsgAttachment','uses' => 'ArticleController@getPostAttachment'));
控制器:
public function getPostAttachment(){
$file = Input::file('file');
return var_dump($file);
}