如何使用laravel php在表中保存多个图像 [英] how to save multiple images in table using laravel php

查看:60
本文介绍了如何使用laravel php在表中保存多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我成为laravel的新手 我想在表中存储多个图像...使用此代码无法保存.

Hi please help me am new to laravel I want to store multiple images in table... With this code am unable to save.

为此帮助我..

在我的视野中

{{Form::open(array('url'=>'businessdirectory/business', 'files'=>true))}}
{{Form::label('image','Upload Image')}}

<div class="form-group">{{Form::file('image[]',array('multiple'=>true))}} 

</div>
{{Form::close()}}

在我的控制器中

 if(Input::file('image'))
        {
        $image = Input::file('image');

        foreach($image as $img) {
        $destination = 'images';
        $filename = $img->getClientOriginalName();
        $path = 'images/'.$filename;
        $uploadSuccess = $img->move($destination,$filename);
        }
        }
        else
        {
            $path='images/default.JPG';
        }
 $business = new Business();    
 $business->image = $path;

推荐答案

不建议将图像存储在数据库中.只需保存图像的路径即可.

It's not advisable to store images on database. Just save the path of the images instead.

如果您确实需要在db上存储映像.确保将列设置为blob,因为它需要更多空间.然后,获取图像内容并键入,然后保存.

If you really need to store image on db. Make sure you set the column to blob as it need more space. Then, get the image content and type, then save it.

<?php
$image = fopen($image_path, 'rb');
// or
$image = file_get_contents($image_path);

$business = new Business;
$business->image = $image;
$business->imageType = "image/gif"; // 
$business->save();

// ...

这篇关于如何使用laravel php在表中保存多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆