<?php
header("Content-type: application/json");
$dir = "images"; 
if(isset($_GET['file'])&&$_GET['file'])
{
	$dir = $_GET['file'];
}
$dirArray = explode('|',$dir);
foreach($dirArray as $key=>$value)
{
	$dirArray[$key] = $value;
}
// Open a known directory, and proceed to read its contents
function find_all_files($dir,&$array)
{
	if (is_dir($dir)) 
	{
		if ($dh = opendir($dir))
		{
			$i=0;
			$curPath = "";
			$curId = "";
			while (($file = readdir($dh)) !== false) 
			{
				if ($file!="." && $file!=".." && $file != '.svn') 
				{
					if(is_dir( $dir.'/'.$file ))
					{
						$array[$file] = array();
						find_all_files($dir.'/'.$file,$array[$file]);
					}
					else
					{
						$curPath = $dir.'/'.$file;
						$curId = explode(".",$file);
						$curId = $curId[0];
						$curPathArr = array('src'=>$curPath,'id'=>$curId);
						// $curPathArr = $curPath;
						array_push($array,$curPathArr);
						//$result[$i] = $dir.'/'.$file;
					}
					$i++;
				}
			}
			
			closedir($dh);
		}
	}
}
$result = array();
foreach($dirArray as $value)
{
	find_all_files($value,$result);
}
//print_r(json_encode($result));
$fp = fopen("./js/images.js", "w");
fwrite($fp,"var resource = ".json_encode($result));
fclose($fp);
echo "console.log('js/images.js updated,上线时请务必删除files.php 文件')";
?> 