read()){ //ファイル名を取得 //現在のディレクトリと上位ディレクトリを除いて if ($fileName != "." && $fileName != ".."){ //ディレクトリでシンボリックリンクでない if (is_dir($fileName) && !is_link($fileName)) { clearstatcache(); thisfunction($path.$fileName. "/"); //再帰処理 chdir($path); }else{ if(ereg ("mp3$", $fileName)){ //mp3ファイルなら $version = id3_get_version( $fileName ); $tag = id3_get_tag( $fileName ); $track = mb_convert_encoding ($tag['title'],"UTF-8","SJIS"); $airtist = mb_convert_encoding ($tag['artist'],"UTF-8","SJIS"); $album = mb_convert_encoding ($tag['album'],"UTF-8","SJIS"); $year = mb_convert_encoding ($tag['year'],"UTF-8","SJIS"); $genre = mb_convert_encoding ($tag['genre'],"UTF-8","SJIS"); $date = date("Y-m-d H:i:s",filemtime($fileName)); $url = mb_urlencode (ereg_replace ($mp3files_dir, "",$path.$fileName)); $path = ereg_replace ($mp3files_dir,"",$path.$fileName); $size = filesize($fileName); //ここでデータベースに入れる " />
itoigawaのブログ
2006-01-04
PCサーバーに保存したmp3をキーワード等から自由に検索できないかとphpにてプログラムを作っています。
mp3のID3タグ情報をデータベースに入れることから始めます。
PHP:ID3 Function id3_get_tag();を利用して取得します。
$dir = dir("."); //ディレクトリ・クラスを使う while ($fileName = $dir->read()){ //ファイル名を取得 //現在のディレクトリと上位ディレクトリを除いて if ($fileName != "." && $fileName != ".."){ //ディレクトリでシンボリックリンクでない if (is_dir($fileName) && !is_link($fileName)) { clearstatcache(); thisfunction($path.$fileName. "/"); //再帰処理 chdir($path); }else{ if(ereg ("mp3$", $fileName)){ //mp3ファイルなら $version = id3_get_version( $fileName ); $tag = id3_get_tag( $fileName ); $track = mb_convert_encoding ($tag['title'],"UTF-8","SJIS"); $airtist = mb_convert_encoding ($tag['artist'],"UTF-8","SJIS"); $album = mb_convert_encoding ($tag['album'],"UTF-8","SJIS"); $year = mb_convert_encoding ($tag['year'],"UTF-8","SJIS"); $genre = mb_convert_encoding ($tag['genre'],"UTF-8","SJIS"); $date = date("Y-m-d H:i:s",filemtime($fileName)); $url = mb_urlencode (ereg_replace ($mp3files_dir, "",$path.$fileName)); $path = ereg_replace ($mp3files_dir,"",$path.$fileName); $size = filesize($fileName); //ここでデータベースに入れる