mysql - 使用 Laravel 将图片存储到 mysql

标签 mysql laravel

我正在尝试使用 laravel 将一些上传图片存储到我的数据库中。一切都很顺利,一切都已存储,但对于文件,他们继续存储 38B 的 bin 文件,我尝试将其读取到 .Txt 文件,它有一个到/Applications/MAMP/tmp/php/phpUzMXbn 的路径。 这是我的功能代码:

Route::post('/FruitCreate',function(Request $request){
$fruit = new fruit;
$fruit->name = $request->name;
$fruit->price = $request->price;
$fruit->picture = $request->image;
$fruit->save();
return redirect('FruitsChangingPricePanel');

我的表单 Blade :

<form enctype="multipart/form-data" method="POST" action="{{ url('FruitCreate') }}" >
{{ csrf_field() }}
<input type="text" name='name'>
<input type="text" name='price'>
<input type="hidden" name="MAX_FILE_SIZE" value="30000000" />
<input type="file" name='image'>
<button type='submit'> submit </button>

感谢您的帮助!!

最佳答案

你可以做的可能是这样的:

$file = $request->file('image'); $imageContent = $file->openFile()->fread($file->getSize()); $fruit = 新水果; $fruit>图片=$imageContent; $fruit>save();

注意:您的列类型必须是 Blob

关于mysql - 使用 Laravel 将图片存储到 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53133711/

相关文章:

mysql - Latin 与 utf8 字符集和索引使用(mysql 5.5)

php - 循环 mysql 表并从 api grabs 更新内容

php - 如何在 Laravel 的搜索表单上将获取参数作为漂亮的 URL 发送?

php - 如何在 Eloquent 中将 "or"与多个 "where"一起使用?

php - 拉维尔 5 : How to retrieve records according to date?

Mysql 列重复

php - 如何在 Google map API 标记上添加数字?

php - 使用 "load data infile"时如何记录错误并将其写入日志文件?

php - 在 Laravel 中获取 MySQL 中的最大值

php - 多表中的 Laravel 关系