save image in public folder instead storage laravel 5

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Title: Save Images and Files in Laravel Public Folder Instead of Storage

Body:

In Laravel, to save your uploaded files or images in the public folder instead of storage, you need to make a few changes. The default Laravel configuration stores user-uploaded content in "storage/app" within the app directory. However, if that's not preferred, you can customize it for your project.

Edit Your Config File

The first step is to open the config/filesystem.php file, where you can modify how Laravel handles uploaded files and images. Make sure the 'disks' array includes a public disk configuration that points to your target directory.

php
'disks' => [
    //... existing disk configurations
    'public' => [
        'driver' => 'local',
        'root'   => storage_path('image'),
        'url'    => env('APP_URL') . '/public',
        'visibility' => 'public',
    ],
]

Here, we've created the public disk configuration with a local driver and its root path set to storage/image. The URL is configured for accessing the public folder via your application's base URL.

Modify Your Route and Controller

Next, update your routes and controllers related to file uploading or image handling. Ensure that you use file-handling methods like $request->file('image') and image properties like $request->image->extension() and $request->image->store(). You can also save the records of uploaded files in a database table, such as pictbl.

Create Your View

In your view template, you can use Laravel's Form facade to handle file uploading along with image viewing. This allows you to display the uploaded images on the same page and save them in the desired location.

html
// In your view file:
{!! Form::open(['url' => 'saved','method' => 'post','files' => true]) !!}
    {!! Form::file('image') !!}
    {!! Form::submit('save') !!}
{!! Form::close() !!}
<img src="{{$patch}}" /> // View uploaded image using stored path from database table

Final Code Example

Combining all the above steps, here's a complete example of saving images in the public folder:

Route:

php
Route::get('pic',function (){
return view('pic.pic');
});
Route::post('saved','test2Controller@save');

Controller:

php
public function save(Request $request)
{
    $file = $request->file('image');
    //Save format
    $format = $request->image()->extension();
    //Save full address of image
    $patch = $request->image()->store('images');<pre><code>$name = $file->getClientOriginalName();

//Save on table
DB::table('pictbl')->insert([
    'orginal_name' => $name,
    'format' => $base,
    'patch' => $patch
]);

return response()
        ->view('pic.pic',compact("patch"));

}

View:

php
{!! Form::open(['url' => 'saved','method' => 'post','files' => true]) !!}
    {!! Form::file('image') !!}
    {!! Form::submit('save') !!}
{!! Form::close() !!}
<img src="{{$patch}}" />

Conclusion

By modifying the config/filesystem.php file and adapting your routes, controllers, and views accordingly, you can manage to save uploaded images in Laravel's public folder instead of default storage locations. This approach allows for greater control over user-uploaded content and better visibility on your website.