Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Resizing uploaded file and saving with the same name in the same location

I try to save an image and resize with Intervention. Filesystem.php has default settings for Laravel 10.

I can successfully save under storage/app/public/image:

$file->storeAs('public/image/', $uniqueFileName);

Than I try to resize and save with same name.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$manager = new ImageManager();
$resizedImage = $manager->make(storage_path('app/public/image/' . $uniqueFileName))->resize(100, 100);
Storage::disk('public')->put(storage_path('public/image/' . $uniqueFileName), $resizedImage);

The problem is, last line creates such a folder and tries to save under this location:

/storage/app/public/Users/tolga/Desktop/project-path/storage/image

Resized images under this location are empty files actually.

>Solution :

You shouldn’t generate a path with storage_path if you are using Storage facade, because storage_path will generate an absolute path, but Storage facade with disk local or public already knows the path to storage. So just write like this

  Storage::disk('public')->put('relative path in storage', $file);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading