How to upload files in Laravel directly into public folder?

How to upload files in Laravel directly into public folder?

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

How to upload files in Laravel directly into public folder?

When your hosting environment restricts the use of symbolic links, the standard php artisan storage:link command becomes unusable. This is a common constraint on shared hosting platforms or servers where the Apache/Nginx configuration blocks the creation of symlinks for security reasons. You might attempt to reconfigure your application's disk layout by modifying the filesystems.php configuration to point the public disk directly at the storage/app/public directory.

However, simply changing the mount point in the configuration array does not automatically make the files accessible via the web root. The Laravel filesystem abstraction layer manages permissions and paths internally, but it does not serve as a proxy for serving static assets unless explicitly told to do so. If you need files uploaded via the public disk to be immediately accessible at URLs like example.com/uploads/image.jpg without a symlink, you must handle the path resolution differently.

Configuring the Public Disk Without Symlinks

The most robust solution that adheres to Laravel's conventions while bypassing the symlink requirement is to configure your application to serve files from a directory that already exists within your web root, or to adjust how the public disk resolves its paths.

Instead of trying to force storage/app/public to become the public folder itself (which breaks the separation between writable storage and static assets), you can define the public disk to point to a subdirectory inside storage/app. For example, you could create a directory at storage/app/public/uploads and configure the public disk in config/filesystems.php to mount there.

To do this, ensure your storage/app/public/uploads directory exists and is writable by your web server user (e.g., www-data). Then, update your filesystems.php configuration:

'disks' => [
    'public' => [
        'driver' => 'local',
        'root'  => storage_path('app/public/uploads'), // Points to a specific subfolder
        'url'   => env('APP_URL').'/storage/app/public/uploads',
        'visibility' => 'public',
    ],
],

By setting the visibility to public and ensuring the URL points correctly, Laravel will treat files stored in this disk as public. When you upload a file using Storage::disk('public')->putFile(...), the framework will store it in the configured root. If your web server is configured to serve static files from the storage/app/public/uploads path (which is often already the case if you are not running the symlink command), the files will be accessible via the URL defined in the config.

Handling Uploads with Form Requests

When implementing file uploads, you often rely on Laravel's form request validation and storage helpers. Even without a symlink, the Storage facade remains fully functional. You can upload files directly into this configured public disk using standard methods:

use Illuminate\Support\Facades\Storage;

// Upload to the 'public' disk defined above
$path = Storage::disk('public')->putFileAs(
    'uploads', // Subdirectory within the root
    $request->file('avatar'),
    'profile.jpg'
);

The key trade-off here is that you lose the convenience of a single storage/app/public bucket for all public assets. Instead, you are managing specific subdirectories within your storage structure. This requires careful attention to your .htaccess rules (on Apache) or Nginx configuration to ensure that requests to /storage/app/public/uploads/* are not blocked by security settings intended to protect the rest of the storage directory.

Alternative: Serving via Route Middleware

If restructuring your filesystems.php feels too rigid for your hosting constraints, another approach is to keep the files in storage/app/public but serve them via a route that explicitly handles the file retrieval. This bypasses the need for the web server to directly serve from the storage directory.

You can create a middleware or a helper route that checks if a file exists in the public disk and returns it with the correct headers. While this adds a layer of abstraction, it guarantees that even if your web server blocks access to the storage folder entirely, you still control the delivery logic within Laravel.

use Illuminate\Support\Facades\Storage;

Route::get('/file/{filename}', function ($filename) {
    $path = Storage::disk('public')->path($filename);
    
    if (!file_exists($path)) {
        abort(404);
    }

    return response()->file($path, [
        'Content-Type' => mime_content_type($path),
        'Content-Disposition' => 'inline; filename="' . $filename . '"',
    ]);
});

This method ensures that file access is mediated by your application logic, which can be preferable on restrictive hosting environments where you cannot manipulate server-level directory permissions or symlink configurations. It also allows you to implement additional security checks before serving the file.

Ultimately, whether you choose to redefine your disk root or serve files programmatically depends on your specific hosting limitations and how much control you need over static asset delivery.

Our network