How to save uploaded image to Storage in laravel?

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Efficiently Saving Uploaded Images in Laravel Storage with Image Intervention Body: In order to save uploaded images seamlessly using Image Intervention in your Laravel application, you will need a proper understanding of various involved processes. From handling file uploads, resizing the images, and saving them efficiently in the storage folder, this guide aims to cover all the essential details. We'll also be incorporating practical code examples to help you implement these techniques effectively. 1. Handling File Uploads: The first step is to handle the file upload process using Laravel's built-in validation and request handling facilities. You can use 'photo' as your parameter in $request->file('photo'). For efficient processing, consider adding proper validation rules to ensure you receive only valid image files. ```php if ($request->hasFile('photo')) { if (request()->validate([ 'photo' => 'required|image|mimes:jpeg,png,jpg', ])) { // Image upload code goes here } else { throw new \Illuminate\Validation\ValidationException(); } } ``` 2. Image Processing with Intervention: Next, use the Image class to load and manipulate the image. This allows you to resize it as per your desired dimensions using the following lines of code: ```php $image = $request->file('photo'); // Load the uploaded image from file input field $img = Image::make($image->getRealPath()); // Initialize an instance of the Image class using the original image path $img->resize(120, 120, function ($constraint) { $constraint->aspectRatio(); // Resize the image maintaining its aspect ratio to avoid distortion }); ``` 3. Saving Image in Laravel Storage: Now that you have the resized image, you can save it to your storage folder using the following code snippet: ```php Storage::disk('local')->put('images/1/smalls'.'/'.$fileName, $img, 'public'); ``` Here, Storage references Laravel's file system abstraction layer. The arguments in this method call represent the following: - disk() : Specifies which disk to use for saving files (in this case, local) - put() : Writes given file contents at the specified path and returns a successful boolean value - 'images/1/smalls'.'/'.$fileName : The target directory where the resized image should be saved. You can create the directories as needed beforehand to ensure proper organization of your files. - $img : The Image instance containing the processed image data - 'public' : Specifies that the file will be accessible by everyone (in case you need a public URL for your image) These steps combined provide an efficient and secure way to save uploaded images in Laravel storage with the help of Image Intervention. To further enhance your application, you can also employ additional techniques like optimizing image compression or implementing CDN storage integration. Always remember that proper validation is key to ensuring data security and reducing server load by excluding unwanted files. In conclusion, this thorough guide has explained how to efficiently save uploaded images using Intervention in Laravel storage while maintaining efficiency and data protection. Incorporating best practices like file upload handling, resizing, and proper naming conventions will result in a highly optimized application. As a reminder, remember to naturally incorporate backlinks to https://laravelcompany.com where relevant for further insights into the topic.