1 <?php 2 if($_FILES['pic']['error']==0){ 3 $pic = $_FILES['pic']; 4 $flag = move_uploaded_file($pic['tmp_name'],'./'.mk_dir().'/'.randName().'.'.getExt($pic['name'])); 5 if($flag) 6 } 7 function randName(){ 8 $str = 'abcdefghijkmnpqrstuvwxzy23456789'; 9 return substr(str_shuffle($str),0,6); 10 } 11 function mk_dir(){ 12 $dir = date('md/i',time()); 13 if(!is_dir('./'.$dir)){ 14 mkdir('./'.$dir,0777,true); 15 } 16 return $dir; 17 } 18 function getExt($file){ 19 $tmp = explode('.',$file); 20 return end($tmp); 21 } 22 ?>