donglang9880 2018-03-12 20:10
浏览 91

在laravel 5.4中的公共目录中上传图像

I have a form for add Hotel And I Want to select image for AnyHotel I use Ajax to save image directory But I Can not upload image in public\images Directory,My Code is Here in Blade:

<div class="form-group has-feedback has-feedback-left">
   <input type="file" id="image">
</div>
<button type="submit"data-dismiss="modal"
id="AddHotel">Add hotel</button>
<script>
$('#AddHotel').click(function (event) {
        var image = $('#image').val();
        var city = $('#city').val();
        $.post('/Add/Hotel', {
                'image' : image,
                '_token': $('input[name=_token]').val()
            },
            function (data) {
                console.log(data);
                window.location.reload();
            });
    });
</script>

And in Controller to save image directory I'm using this code:

public function Store(request $request)
{
    $hotel->image = $request->image;
    $hotel->save();
    return $request->all();
}

My Problem is here That When I Print this image from DB image should be in public Directory,How I Can upload image in directory?

  • 写回答

3条回答 默认 最新

  • dton37910 2018-03-12 20:31
    关注

    Laravel stores files in the storage directory by default. You can create a symlink as described here, https://laravel.com/docs/5.6/filesystem#the-public-disk, or create another disk in your filesystems config file.

    The former is probably your better option.

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大