LoginSignup
1
0

More than 5 years have passed since last update.

PHPで指定ディレクトリのファイル名取得

Last updated at Posted at 2017-12-19

ファイル名取得

  • Pythonだとlistdir関数を使って指定ディレクトリのファイル名を取得できるのですが,自分はPHPでファイル名取得することのほうが多いので,一応メモ書きで.

コード

  • scandir 関数を使います.

$dir = ""; //ディレクトリの指定
$files = scandir($dir);

  • これで$filesに配列として,ファイル名が代入されます.
    • これだとディレクトリ内の " . " と " .. " が含まれる.

なので for文とかで確認したいときは ↓

for($i=2;$i<count($files);$i++){ //$i = 2から始める
    echo $files[$i];
}
1
0
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
1
0