How to get a file stored in storage/app/?

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Mastering File Storage in Laravel: How to Access Files Stored in `storage/app` Storing and retrieving files is a fundamental task in any web application, but navigating the file system within a framework like Laravel can often lead to confusion regarding permissions, paths, and public access. Many developers run into issues when trying to link a private storage directory to the web root, resulting in frustrating 404 errors. This post will dive deep into exactly how Laravel manages file storage, demystify the role of `storage:link`, and provide the definitive steps to ensure your files are accessible via a public URL. ## Understanding Laravel's Filesystem Abstraction Laravel abstracts file operations through its `Storage` facade, which allows you to interact with various "disks" (like local, public, or S3). When you use `Storage::put()`, the file is actually written to a specific location defined by your filesystem configuration. By default, Laravel uses the `local` disk for storage. The path you are referring to, `storage/app/public`, is where Laravel stores files intended for public access. However, this directory is deliberately kept outside the web root for security reasons. To make these files accessible via a browser, we need a mechanism to create a symbolic link from the private storage location into the publicly accessible `public` directory. ## The Role of `php artisan storage:link` The command `php artisan storage:link` is the crucial bridge between your application's internal file structure and the web server's viewable public assets. When you run this command, Laravel creates a symbolic link inside the `public` directory that points to the actual storage location, which is typically `storage/app/public`. This effectively makes the contents of `storage/app/public` accessible through the web root path `/storage`. If you are following the setup outlined in the official documentation regarding filesystem configuration, understanding this link is essential for proper asset handling. For more details on structuring your application and configuration, always refer to the resources provided by [laravelcompany.com](https://laravelcompany.com). ## Storing Files Correctly with the Storage Facade When you use the `Storage` facade, you must specify which disk you are targeting. For publicly accessible files, we typically target the `public` disk configuration. Here is the correct workflow for storing an image: ```php use Illuminate\Support\Facades\Storage; // Store the file on the 'public' disk. // Laravel handles putting it into storage/app/public/images/blah.png $path = 'images/blah.png'; $file = $request->file('image'); // Assuming you are handling an upload if ($file) { // Store the file, specifying the 'public' disk Storage::disk('public')->put($path, $file); } ``` This approach ensures that the file is correctly placed within the structure defined by your `config/filesystems.php` settings, maximizing consistency across your application. ## Troubleshooting the 404 Error The reason you are encountering a 404 error when trying to access URLs like `http://localhost:8000/storage/images/blah.png` is often related to how Laravel resolves paths versus how the web server handles symbolic links, especially in local development environments. If you have run `php artisan storage:link`, and your configuration correctly defines the public disk root (as shown by the structure in `config/filesystems.php`), the path should resolve correctly. The issue often lies either in missing permissions or a misconfiguration of the web server's document root mapping. **Best Practice:** Always trust the framework's provided methods over manual file permission changes for primary access. Ensure that your environment variables, such as `APP_URL`, are set correctly to ensure generated URLs point to the correct base path. If you continue to face issues, review the specific documentation regarding filesystem configuration on [laravelcompany.com](https://laravelcompany.com) to verify that your disk settings align perfectly with your symbolic link setup. ## Conclusion Getting file storage working smoothly in Laravel is less about manually managing directories and more about correctly leveraging the framework's built-in abstractions. By understanding how `Storage` interacts with configured disks, properly executing `storage:link`, and ensuring your filesystem configuration aligns, you can reliably serve files to your users. Focus on the abstraction layer; let Laravel handle the difficult file system details!