How to upload files in Laravel directly into public folder?

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Efficiently Upload Files in Laravel Using Public Folder - A Comprehensive Guide Body:

In situations where the hosting server doesn't support links, or you can't use php artisan storage:link, it's crucial to find an efficient way to handle file uploads in Laravel directly into the public folder. While it is possible to configure your filesystems.php file to reference the public folder, it may not work as expected in every case. Instead, let's explore alternative ways using Laravel libraries and PHP methods.

request()->file('image')->storePublicly()

The first approach involves storing the uploaded files directly into the public folder by utilizing Laravel's native file storage functionality. Using the Illuminate\Http\Request's file method, you can store an uploaded file by calling: $image = request()->file('image'); Storage::disk('public')->put($filename, file_get_contents($image)); With this code snippet, the file is saved in storage/app/public, and you'll have to copy or symlink it manually into your public folder for access. If you prefer not to do so, you can use a dedicated utility method: $image = request()->file('image'); Storage::disk('public')->put($filename, file_get_contents($image), 'public'); This saves the file directly into /public/uploads. Remember to update your public folder's .htaccess file to allow file access from your website.

use League\Flysystem\Adapter\Local;

If you want a more comprehensive solution, you can use Laravel's native File System Library with the League\Flysystem package. First, install it using: composer require league/flysystem Next, extend your current filesystem configuration in config/filesystems.php: ```php 'public' => [ 'driver' => 'local', 'root' => storage_path('app/public') ], ``` Now, you can save your file directly into the public folder using: $image = request()->file('image'); Storage::disk('public')->put($filename, file_get_contents($image)); In case of a symlink failure or when links are unavailable, this method works effectively. However, keep in mind that this configuration might not be the best way to handle storage if you have multiple users uploading files simultaneously.

Conclusion:

In conclusion, there are various methods for handling file uploads with Laravel and ensuring they are saved directly into your public folder. The native Laravel functions and PHP methods provided above will help you find the most suitable solution depending on your particular needs and constraints. Always remember to check for potential concurrency issues when dealing with multiple users uploading files, and consider alternative approaches if necessary. Happy coding! Remember that each approach has its pros and cons. Choose wisely based on your specific project's requirements and the server configuration you are working with. For more details about file management in Laravel, refer to our well-detailed blogs at Laravel Company Blog!