Chr*_*z74 20 storage file laravel
对应的是什么:
if (!File::exists($path))
Run Code Online (Sandbox Code Playgroud)
使用Storage::在Laravel 5.1?
任何人?
pra*_*ava 29
试试这个:
// To check if File exists in Laravel 5.1
$exists = Storage::disk('local')->has('file.jpg');
// To check if File exists in Laravel 5.2
$exists = Storage::disk('local')->exists('file.jpg');
Run Code Online (Sandbox Code Playgroud)
Pra*_*eek 11
如果要检查目录是否存在并创建一个目录(如果不存在),则此代码将适用于您.
if(!Storage::exists('/path/to/your/directory')) {
Storage::makeDirectory('/path/to/create/your/directory', 0775, true); //creates directory
}
Run Code Online (Sandbox Code Playgroud)
Ale*_*nin 10
如果要检查目录,请尝试以下操作:
if (Storage::directories($directory)->has('someDirectory')) {
....
Run Code Online (Sandbox Code Playgroud)
https://laravel.com/docs/5.1/filesystem#directories
https://laravel.com/docs/5.1/collections#method-has
有两件事需要检查:(1) 路径是否存在,(2) 路径是否是目录。
这将检查路径是否存在(Laravel 5.2+ 的语法),无论它是文件还是目录:
Storage::exists('your-path') // bool
Run Code Online (Sandbox Code Playgroud)
一旦您知道它存在,这将确认该路径是一个目录:
Storage::getMetadata('your-path')['type'] === 'dir'
Run Code Online (Sandbox Code Playgroud)
底层Flysystem库将在检查文件系统(可能是本地或远程)时缓存它可以缓存的内容,因此在正常情况下这两个函数只会对文件系统进行一次调用。
小智 5
laravel 5.5 使用 Storage Facade 的另一种方式。
use Illuminate\Support\Facades\Storage;
if(Storage::exists('/mnt/files/file.jpg')) {
dd('file esxists');
} else {
dd('no file found');
}
Run Code Online (Sandbox Code Playgroud)