laravel file does not exist or is not readable

laravel file does not exist or is not readable

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

Stefan Bogdanescu

Founder & Senior Architect

The "File Does Not Exist" Paradox in Laravel File Handling

You are encountering a classic symptom of a logic error rather than a filesystem issue. The file physically exists on the disk, and your database records reflect the upload successfully. Yet, when you attempt to retrieve that file via a URL, Laravel throws Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException: /var/www/html/public/files/idus/... does not exist.

This discrepancy points directly to how Laravel resolves relative paths versus absolute paths, and specifically, how the Storage facade interacts with your application's directory structure.

The Path Resolution Trap

In your controller, you define the destination for the uploaded file like this:

$location = public_path('files/idus/');
$request->file('coDoc')->move($location, $filename);

This line correctly moves the physical file into your public directory. However, later in the same method, you construct the URL for the email template using a relative path:

'files' => url('files/idus', $company->files),

The helper function url() generates a URL based on the current public base path. If your application is running from the root of your project (e.g., /var/www/html), this should theoretically work. The issue often arises if the public_path() and url() helpers are resolving differently due to configuration or if the file path stored in the database is not exactly what the URL helper expects when accessed by a browser.

More critically, look at how you are storing the filename:

$company->files = $filename;

You are storing just the relative path (e.g., username-Company-Prove-Documents-abc123.zip) into the database. While this is a common pattern, it relies on the web server being served from the exact same root that Laravel's public_path() assumes. If your web server (Apache or Nginx) is configured to serve the application from a different directory (e.g., /var/www/myapp while Laravel expects /var/www/html), the relative URL will fail to resolve, triggering the "file does not exist" error even though the file is physically there.

Using Absolute Paths for Reliability

To decouple your database storage from potential web server configuration quirks, it is often safer to store the absolute filesystem path or ensure the URL helper is explicitly given the correct base. However, the most robust approach in Laravel 9+ and later versions is to leverage the Storage facade consistently.

Instead of manually moving files to a directory managed by public_path(), consider using the disk system. If you define a disk in your config/filesystems.php that points directly to your uploads folder, you can interact with it without worrying about public_path() mismatches.

// Define a disk in config/filesystems.php or create it dynamically
Storage::disk('local')->putDirectory('files/idus');

// Use the storage facade for moving and checking
$filename = $company->user->username . '-Company-Prove-Documents-' . str_random(10) . '-' . time() . '.' . $coDoc->getClientOriginalExtension();

Storage::disk('public')->put('files/idus/' . $filename, file_get_contents($coDoc->getRealPath()));

While put is not ideal for large files due to memory usage, it highlights the abstraction layer. For large uploads, stick to the move method but ensure you are storing a path that matches exactly what your web server expects.

Debugging the URL Construction

The error message specifically mentions that the file cannot be found. This usually happens when the browser requests /files/idus/filename.zip, but the web server is looking in the wrong place relative to DocumentRoot.

If you are using a shared hosting environment or a specific Docker setup, verify your .htaccess configuration. Ensure there are no rewrite rules interfering with direct file access in that subdirectory.

Additionally, check your database logic for race conditions. In your snippet:

$oldFilename = $company->files;
// ... save happens here ...
Storage::delete($oldFilename);

If $company->files was null or empty before the upload, the check !empty($company->files) prevents deletion. However, if you update the column but haven't flushed the cache (if using file system caching for your app's config), it might not reflect immediately. But more likely, the issue is simply that the URL generated by url('files/idus', $company->files) assumes a base path that doesn't match the actual server configuration.

Recommended Fix

Update your email data generation to use an absolute URL or ensure the relative URL matches your server's DocumentRoot exactly.

'files' => url('/files/idus/' . $company->files), 

By explicitly starting the path with a slash, you force Laravel to treat it as a root-relative path rather than app-relative, which can prevent issues if your base_url configuration is slightly off. Alternatively, use the full public URL of your application domain:

$fullUrl = Storage::url('files/idus/' . $company->files);
'files' => $fullUrl,

Using Storage::url() is generally preferred because it handles disk prefixes and absolute path logic internally, removing the ambiguity between public_path() and the web server's root. This ensures that regardless of how your project is mounted, the URL returned in the email will resolve to the correct physical file location.

Our network