|
 |
1³â Àü |
<?php
$search = isset($_POST['audioPath'])? str_replace("/mp3files","",$_POST['audioPath']) : '';
$dir ='./mp3files'.$search;
echo getCurrentFileList($dir);
function getCurrentFileList($dir){
$web_url = "http://localhost/_test";
$valid_formats = array("mp3","wav");
$handle = opendir($dir); // µð·ºÅ丮ÀÇ ÇÚµéÀ» ¾ò¾î¿È
// ÁöÁ¤ÇÑ µð·ºÅ丮¿¡ ÀÖ´Â µð·ºÅ丮¿Í ÆÄÀϵéÀÇ À̸§À» ¹è¿·Î ÀоîµéÀÓ
$R = array(); // °á°ú ´ãÀ» º¯¼ö »ý¼º
$cnt = 0;
while ($entry = readdir($handle)) {
if($entry == '.' || $entry == '..') continue;
$getExt = pathinfo($entry, PATHINFO_EXTENSION); // ÆÄÀÏ È®ÀåÀÚ ±¸Çϱâ
$curdir = substr($dir,1,strlen($dir)-1); // ÇöÀç Æú´õ Á¤º¸
if(empty($getExt)){
$subdir = $dir.'/'.$entry;
$subdir = substr($subdir,1,strlen($subdir)-1);
array_push($R,array("isFile"=>1,"fileName"=>$entry,"filePath"=>$subdir,"curPath"=>$curdir));
} else {
if(in_array($getExt, $valid_formats)){
$filepath = $dir.'/'.$entry;
$filepath = substr($filepath,1,strlen($filepath)-1);
array_push($R,array("isFile"=>2,"fileName"=>$entry,"filePath"=>$filepath,"curPath"=>""));
}
}
// »óÀ§Æú´õ
$check = str_replace("/mp3files","",$curdir);
if(strlen($check)>0 && $cnt < 1){ // »óÀ§Æú´õ´Â 1ȸ¸¸ Ãß°¡µÇµµ·Ï ó¸®
$filePath = substr($curdir,0,strripos($curdir, "/")); // »óÀ§Æú´õ
$updir = substr($filePath,0,strripos($filePath, "/")); // Â÷»óÀ§Æú´õ
array_push($R,array("isFile"=>0,"fileName"=>"»óÀ§Æú´õ","filePath"=>$filePath,"curPath"=>$updir));
$cnt++;
}
}
closedir($handle);
sort($R); // ¾Èµå·ÎÀ̵忡¼ °¡³ª´Ù¼øÀ¸·Î Á¤·ÄÇϱâ À§ÇØ
return json_encode(array("result"=>$R));
}
?> |
|
̵̧ : 112 |
̵̧
¸ñ·Ï
|
|