Thursday, June 12, 2008

php ファイル名の一覧の取得

<?php

$regex = "([^\/]+).mp3$";
$dir =".";
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ( preg_match ( "/".$regex."/", $file, $matches) ) {
echo $file;
$files[] = $file;
// $matches[1]で名前だけとるのもあり。
}
}
closedir($handle);
}

?>

No comments: