alex alex - 1 month ago 6
PHP Question

Laravel: check file existence without extension

I'm saving files in server only with a md5 hashed name without extension.
I noticed laravel

Storage::exists()
method will return true even if file does not exists. in fact laravel assume file name as a directory name. is there any way to force laravel to check file existence ?

Answer

Actually, it's because the way PHPs file_exists function works. Anyways, you may use something like this:

if(is_file('68e109f0f40ca72a15e05cc22786f8e6')) {
    // ...
}

Also, you may try glob like this:

$all = glob('*'); // Read everything from current directory in array
if(in_array('68e109f0f40ca72a15e05cc22786f8e6', $all)) {
    // ...
}

There are more ways to do this but why not use an extension?

Comments