Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

timgavin's avatar

Checking if file exists

This returns 'yes'

if(file_exists('/mnt/files/snow.jpg')) {
    dd('yes');
} else {
    dd('no');
}

This returns 'no'

use Illuminate\Support\Facades\Storage;
if(Storage::exists('/mnt/files/snow.jpg')) {
    dd('yes');
} else {
    dd('no');
}

This returns nothing. not even an error message.

use Illuminate\Http\File;
if(File::exists('/mnt/files/snow.jpg')) {
    dd('yes');
} else {
    dd('no');
}

Why? I thought I could at least use Storage::exists() to check if a file exists? The docs tell me I can, or am I misreading?

0 likes
4 replies
bobbybouwmann's avatar
Level 88

The Storage facade uses the storage that is active in your config files (config/filesystems.php). Note that this defaults to local. The root path is set for each storage option. In the case of local it's pointing to storage/app out of my head.

So it's not possible to retrieve a file with Storage that is not in your project without weird hacks!

Shafqat_ali's avatar

@timgavin Maybe try the documentation way to specify storage disk exist i.e. You can find it here

$exists = Storage::disk('s3')->exists('file.jpg');
ektapuri's avatar

I am new to laravel and was dealing with images, what i understood here is, considering images are stored in public/images folder

file_exists needs full path to image like var/.../...//storage/images/ $image_path = storage_path(images/) file_exists(storage_path($image_path) this will return true

Whearas, Storage Facade only needs images/

$image_path = "images/"; Storage::exists($image_path) this will return true

Please or to participate in this conversation.