简体   繁体   English

Laravel:检查文件是否存在而没有扩展名

[英]Laravel: check file existence without extension

I'm saving files in server only with a md5 hashed name without extension. 我只使用没有扩展名的md5哈希名称来保存服务器中的文件。 I noticed laravel Storage::exists() method will return true even if file does not exists. 我注意到即使文件不存在,laravel Storage::exists()方法也会返回true。 in fact laravel assume file name as a directory name. 事实上,laravel假定文件名为目录名。 is there any way to force laravel to check file existence ? 有没有办法强制laravel检查文件存在?

Actually, it's because the way PHP s file_exists function works. 实际上,这是因为PHPfile_exists函数的工作方式。 Anyways, you may use something like this: 无论如何,你可以使用这样的东西:

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

Also, you may try glob like this: 另外,你可以试试像这样的glob

$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? 有更多的方法可以做到这一点,但为什么不使用扩展?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM