使用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 Photo Viewer无法打开此图片,因为该文件似乎已损坏,损坏或太大。
答案 0 :(得分:1)
您必须使用file_get_contents
方法才能获得图像:
尝试:
Storage::disk('blockcontentimages')->put($fileName, file_get_contents($image));