PHP・ディレクトリ配下にあるファイルを取得 [備忘録]
< PHP・ディレクトリ配下にあるファイルを取得 >
■実装例 /*********************************** * ディレクトリ配下のファイルを取得 ***********************************/ function getFileList(){ $list = array(); $list_dir = "./playlist"; /*-------------------------------- * ディレクトリ指定 *--------------------------------*/ $root = getcwd(); // 現在のディレクトリを取得 $path = $root.$list_dir; chdir($path); // ファイルのあるディレクトリに移動 /*-------------------------------- * ディレクトリ配下のファイルを取得 *--------------------------------*/ $strDir = @opendir($path); while(false !== ($file = readdir($strDir))){ if(is_file($file)){ // ファイル名取得 $file_name = basename($file, '.csv'); // 拡張子を取る $list[$file] = $file_name; } } @closedir($strDir); return($list); } |
タグ:PHP
コメント 0