且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用laravel php在表中保存多个图像

更新时间:2023-09-28 11:21:40

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

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();

// ...