Web Programming >> PHP Programming
|
[목차] |
제4장 파일처리 프로그램
5. Music Box 단계 1. 디렉토리 구조 musicbox/라는 디렉토리를 만들고, 하위 디렉토리로 play/와 gayo/, oldpob/이라는 디렉토리를 만든다. 아래와 같은 디렉토리 구조가 된다. musicbox/ | +---- play/ | +---- gayo/ | +---- oldpop/ | +---- index.html | +---- menu.htmlplay/디렉토리의 권한설정을 707로 바꾼다. 메모장에서 index.html과 menu.html을 만들어, musicbox/디렉토리 밑에 올린다.
단계 2. 실행 프로그램 짜기(index.html) <? if($task == "gayo") $title = "가요 세상"; else if($task == "oldpop") $title="Greatest Hits Pop Song"; ?> <html> <head> <title><?echo("$title");?></title> <style type="text/css"> <!-- a:link,a:visited,a:active { text-decoration : none;color:red; } a:hover { text-decoration : underline; color : blue; } TABLE, TD, TR, TH { font-size : 10pt;color:black; } //--> </style> </head> <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red" <? if($play == "yes") echo("onUnload=\"logout()\"");?> oncontextmenu="return false"> <? include("menu.html"); $php_self = $PHP_SELF; if($task == "") $task = "gayo"; if($play == "yes" ) { if($play_file_name == "") { echo("<meta http-equiv='Refresh' content='0; URL=./?task=$task'>"); } $play_file = "./play/".$play_file_name; //echo("$play_file"); if(!file_exists($play_file)) { $tempfp = fopen($play_file, 'w'); fclose($tempfp); } if(!is_array($song)) { echo("선택된 노래가 없습니다. 노래 선택 화면으로 이동합니다."); echo("<meta http-equiv='Refresh' content='2; URL=./?task=$task'>"); exit; } if($shuffle == "Y"){ srand(time()); shuffle($song); } if($playfp = fopen($play_file, 'a')) { $i=0; while(each($song)) { if(strcmp($song[$i],"")) { $comment = $song[$i]; $comment = "http://leelab.co.kr/~jklee/musicbox/".$task."/".$comment; fwrite($playfp, $comment, strlen($comment)); } fwrite($playfp, "\n", strlen("\n")); $i++; } fclose($playfp); } else { echo("$play_file 을 열 수 없습니다."); exit; } if($loop == "Y") $loop="true"; else $loop="false"; if($autostart == "") $autostart = "true"; ?> <SCRIPT LANGUAGE="JavaScript"> <!-- HIDE FROM OTHER BROWSER function logout() { location.href="<?echo("./?task=$task")?>&play=no&play_file_name=<?echo("$play_file_name");?>"; } // STOP HIDING --> </SCRIPT> <center> <font size=5 face=굴림><?echo("$title");?></font> <p><embed src="<?echo("$play_file");?>" width="0" height="0" border="0" hidden="true" autorewind="true" autostart="<?echo("$autostart");?>" loop="<?echo("$loop");?>" type="application/x-mplayer2" ><br></p> <p> 잠시 기다리시면 음악이 나옵니다.</p> <font size=2> <a href="<?echo("./?task=$task")?>">목록으로 가기</a> </center> <? } else if($play == "no") { if($play_file_name != "") { $play_file = "./play/".$play_file_name; unlink($play_file); } echo("<meta http-equiv='Refresh' content='0; URL=./?task=$task'>"); } else { $new_play = time(); $play_file_name = $new_play.".m3u"; ?> <script language="javascript"> <!-- function profileWindow(ref) { var window_left = (screen.width-300)/2; var window_top = (screen.height-100)/2; window.open(ref,"profileWin",'width=300,height=100,status=no,scrollbars=auto, top=' + window_top + ',left=' + window_left + ''); } function start_music() { signform.submit(); } function select_all() { signform.play.value = "all"; signform.submit(); } function clear_all() { signform.play.value = ""; signform.submit(); } //--> </script> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 width="600" align=center> <form name="signform" method="post" action="./"> <input type='hidden' name='task' value='<?echo("$task");?>'> <input type='hidden' name='play' value='yes'> <input type='hidden' name='play_file_name' value='<?echo("$play_file_name");?>'> <TR><TD colspan=2 height=50 align=center> <font size=5 face=굴림><?echo("$title");?></font> </td> </tr> <TR><TD colspan=2 height=50 > <input type="button" value=" Play " onclick="start_music()"> <input type="button" value=" 전체선택 " onclick="select_all()"> <input type="button" value=" 선택 취소 " onclick="clear_all()"> <input type="reset" value=" 다시 선택 " > </td> </tr> <TR><TD width=25 > <input type="checkbox" name="loop" value="Y"> </td> <td> <font size=2 color=blue>반복해서 들으시려면, 선택하세요. </td> </tr> <TR><TD width=25> <input type="checkbox" name="shuffle" value="Y"> </td> <td> <font size=2 color=blue>랜덤으로 들으시려면, 선택하세요. </td> </tr> <? $dirptr = opendir("./".$task); if($dirptr) { $song_total_num=0; while($song_name[$song_total_num] = readdir($dirptr)) { if(!(strcmp($song_name[$song_total_num],".") && strcmp($song_name[$song_total_num],".."))) continue; $song_total_num ++; } sort($song_name); for($i=1;$i<=$song_total_num; $i++) { $filename = explode(".", $song_name[$i]); ?> <TR><TD width=25 height=20> <input type="checkbox" name="song[]" value="<?echo("$song_name[$i]");?>" <?if($play =="all") echo(" checked");?>> </td> <td><?echo("$filename[0]");?></td> </tr> <? } closedir($dirptr); } else echo("오류가 있습니다."); ?> <TR><TD colspan=2 height=50 > <input type='hidden' name='song_total' value='<?echo("$song_total_num");?>'> <input type="button" value=" Play " onclick="start_music()"> <input type="button" value=" 전체선택 " onclick="select_all()"> <input type="button" value=" 선택 취소 " onclick="clear_all()"> <input type="reset" value=" 다시 선택 " > </td> </tr> </form> </table> <p> </p> <? } ?> </body> </html> 3. 메뉴( menu.html )
<TABLE border=0 align=center width=500> <TR> <TD><A HREF="./?task=gayo">가요세상</A> <A HREF="./?task=oldpop">Greatest Hits Pop Song</A> </TD> </TR> </TABLE> <hr size=1>기타 추가사항이 있으면, 참고하여 수정하세요
|
[목차] |