php - Laravel 5.0 使用自定义 Filsystem 将图像保存为损坏或损坏
问题描述
我在使用 ajax 上传后保存图像,但图像被保存为损坏。
我的磁盘
'blockcontentimages' => [
'driver' => 'local',
'root' => public_path() . '/static/core/img/templates',
],
我如何存储我的图像:
$image = $request->file('content');
$file = $image->getClientOriginalName();
$fileName = '/static/core/img/templates/' . $blockNewsletterPivotId . '_' . str_replace(' ', '_', $file);
Storage::disk('blockcontentimages')->put($fileName, $image);
$image 的 dd:
UploadedFile {#27
-test: false
-originalName: "cloud.jpg"
-mimeType: "image/jpeg"
-size: 54754
-error: 0
}
我不确定我在这里做错了什么,为什么它被保存为损坏或损坏的文件。
编辑
当我尝试打开保存的文件时,我在照片查看器中收到此错误消息:
Windows 照片查看器无法打开此图片,因为该文件似乎已损坏、损坏或太大。
解决方案
您必须使用file_get_contents
方法才能获取图像:
试试看:
Storage::disk('blockcontentimages')->put($fileName, file_get_contents($image));
推荐阅读
- google-maps - Location/GeoLocator/GeoLocation 没有返回我的纬度和经度
- oracle - oracle 语句中的 TRUSTED/UNTRUSTED 关键字
- javascript - JavaScript 可以实现并行性吗?
- c++ - 将字符串向量移动到另一个字符串向量
- concurrency - 如何在负载运行器场景中计算以下任务的平均用户并发?有人能帮我吗?
- python - 通过加倍和连接来“扁平化”熊猫数据框?
- javascript - .find() 方法:我如何返回一个布尔值而不是我找到的对象?
- vue.js - 我想在本地使用Vue,但它不起作用
- css - CSS布局:如何在N个元素之后打破第一列,并在第二列中跟随,仅使用CSS?
- node.js - 每次更改使用的默认 Node 版本时是否需要“npm install”?