【问题标题】:Laravel 5 multiple IMAGES upload inside form and saving img location in DBLaravel 5 多个图像在表单中上传并在数据库中保存 img 位置
【发布时间】:2016-07-26 17:36:28
【问题描述】:

我有表单,里面有文本字段、复选框、选择和文件上传。我需要的是仅上传图像并将图像的位置传递给控制器​​,以便我可以将它们保存到数据库。

这是我的控制器:

    public function spremi(){

    $input= Request::all();
    Oglas::create($input);
    return redirect('other');
}

路线:

Route::post('other', 'OglasController@spremi');

如果我返回请求,或者为我的数据库创建“Oglas”,我得到的只有图像名称。图像没有上传到任何地方? (等。存储/..,公共/...)。

{{Form::file('slike', ['class' => 'field']) }}

我的问题是:如何让事情以最好的方式工作,所以我的图像被上传到一个文件夹,并且只有它们的正确位置被保存在 db 中?

提前谢谢大家。

【问题讨论】:

标签: php mysql forms file-upload laravel-5.2


【解决方案1】:

这是针对当时 1 个图像移动/上传进行测试的:

    $image = $request->file('slike');
    $destinationPathImg = '/your path/images/';

    if (!$image->move($destinationPathImg, $image->getClientOriginalName())) {
        return 'Error saving the file.';
    }

您的 FORM 需要有 multipart/form-data:

{!! Form::open(['url'=>'/other','enctype'=>"multipart/form-data"]) !!}

【讨论】:

    猜你喜欢
    • 2014-08-09
    • 2019-08-09
    • 1970-01-01
    • 2010-09-22
    • 2017-07-16
    • 2020-04-26
    • 2021-06-09
    • 2015-10-16
    • 2020-06-13
    相关资源
    最近更新 更多