使用Uikit 2 + Laravel上传图像

时间:2019-02-26 13:48:04

标签: laravel upload uikit

我有用于上传图像的基本脚本Uikit 2,它没有在公共图像目录上上传图像。为什么?

upload.blade.php

<form id="upload" action="#" method="POST" enctype="multipart/form-data">
    <div id="upload-drop" class="uk-placeholder">
        <i class="uk-icon-upload uk-icon-large"></i>Select files<input id="upload-select" name="files[]" type="file" accept="image/*" multiple>
    </div>
    <div id="progressbar" class="uk-progress uk-hidden">
        <div class="uk-progress-bar" style="width: 0%;">...</div>
    </div>
</form>

$(function(){

    var progressbar = $("#progressbar"),
        bar         = progressbar.find('.uk-progress-bar'),
        settings    = {

            action: '{{ route('upload') }}', // upload url
            allow : '*.(jpg|jpeg|gif|png)', // allow only images

。 。

路由文件:

Route::post('/upload',['as' => 'upload', 'uses' => 'upload@upload']);

控制器文件 upload.php

class upload extends Controller
{
    public function upload(Request $request)
    {
        $images = $request->file('files');
        foreach($images as $key => $image) {
            $filename = $image->getClientOriginalExtension();
            $image->move(public_path().'/images',$filename);
        }    
    }
}

1 个答案:

答案 0 :(得分:0)

要上传文件数组,您应该使用files方法而不是file方法:

$images = $request->files('files');