<?php
class IndexModule extends CommonModule{

	public function index(){

    	//保存目录
		$upload_save_path =  C('UPLOAD_SAVE_PATH') ? C('UPLOAD_SAVE_PATH') : '../Uploads/';
		//上传目录
		$upload_path = trim($_GET['dir'])=='' ? 'image' : trim($_GET['dir']);

		//定义上传的文件扩展名
		$ext_type = C('UPLOAD_ALLOW_TYPE');
		if (empty($ext_type)){
			$ext_type = array(
	            'IMAGE' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),
	            'MEDIA'  => array('swf', 'flv', 'mp3','mp4','f4v','wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),
	            'FILE'   => array('doc', 'docx', 'xls', 'xlsx', 'zip', 'rar', 'gz', 'bz2','pdf'),
		);}

		//允许上传文件大小
		$file_size = C('UPLOAD_ALLOW_SIZE')=='' ? 2097152 : C('UPLOAD_ALLOW_SIZE');
		$upload   = new Upload($upload_save_path.$upload_path.'/'.date("Ymd"),$ext_type[strtoupper($upload_path)],$file_size);
		$uplofile = $upload->upload();

		if($uplofile){
			if (C('WATER_ON') && in_array($uplofile[0]['ext'],$ext_type['IMAGE'])){
				$water = new Image();
				$water->water($uplofile[0]['path']);
			}
			if (C('THUMB_ON') && in_array($uplofile[0]['ext'],$ext_type['IMAGE'])){
				$thumb = new Image();
				$thumb->thumb($uplofile[0]['path']);
			}
			echo json_encode(array("msg"=>'上传成功',"url"=>$uplofile[0]['path'],"result" => '1'));
		}else{
			echo json_encode(array("msg"=>$upload->getError(),"error" => 1));
		}
	}
}