Michael
Michael

Reputation: 576

Laravel 5.0 saves image as damage or corrupted with custom Filsystem

I am saving an image after upload with ajax but the image gets saved as damaged.

My disk

'blockcontentimages' => [
    'driver' => 'local',
    'root'   => public_path() . '/static/core/img/templates',
],

How I store my image:

$image = $request->file('content');

$file = $image->getClientOriginalName();
$fileName = '/static/core/img/templates/' . $blockNewsletterPivotId . '_' . str_replace(' ', '_', $file);

Storage::disk('blockcontentimages')->put($fileName, $image);

dd of $image:

UploadedFile {#27
  -test: false
  -originalName: "cloud.jpg"
  -mimeType: "image/jpeg"
  -size: 54754
  -error: 0
}

I am not sure what I am doing wrong here why it's being saved as a damaged or corrupted file.

EDIT

When I try to open the saved file I get this error message in my photo viewer:

Windows Photo Viewer can't open this picture because the file appears to be damaged, corrupted, or is too large.

Upvotes: 0

Views: 451

Answers (1)

H45H
H45H

Reputation: 1017

you have to use file_get_contents method in order to get image :

Try like :

Storage::disk('blockcontentimages')->put($fileName, file_get_contents($image));

Upvotes: 1

Related Questions