【发布时间】:2015-06-03 14:24:01
【问题描述】:
我想使用 Laravel 4.2 将“Dropzone”合并到我的网站中,我在他们的官方网站 here 中找到了一个示例。
但是当我将它添加到我的表单时,表单会改变行为,我无法在控制器中处理图像。你能给我一个使用 Laravel 4.2 的 dropzone 的基本示例吗?
【问题讨论】:
标签: laravel laravel-4 dropzone.js
我想使用 Laravel 4.2 将“Dropzone”合并到我的网站中,我在他们的官方网站 here 中找到了一个示例。
但是当我将它添加到我的表单时,表单会改变行为,我无法在控制器中处理图像。你能给我一个使用 Laravel 4.2 的 dropzone 的基本示例吗?
【问题讨论】:
标签: laravel laravel-4 dropzone.js
<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);
}
【讨论】:
这是我的查看代码:
{{ 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);
}
【讨论】: