LoginSignup
4
4

More than 3 years have passed since last update.

【サルが書く】Laravelでファイルが存在するかを確かめる

Last updated at Posted at 2020-01-27

うっきょ

ファイルが存在するかを確かめたい。
PHPにはfile_existsがありますが、Laravelライクで書いていきたい。
なので、Fileファサードを使用してファイルが存在するかを確かめます。

用法

<?php
use Illuminate\Support\Facades\File;

.
.
.

$filepath = '/dir/hoge.txt';

if (\File::exists($filepath)) {
    echo "$filepath が存在します";
} else {
    echo "$filepath は存在しません";
}

使用場面

使う場面としては File::delete() を使用して、ファイルがちゃんと消えているかを確認する際に File::exists を使用して、ファイルが消えていることを確認できます。

参考資料

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4