function upfile($file){
$error=$file['file']['error'];
if($error==4){
echo "请选择需要上传的文件";
exit;
}
if($error==1){
echo "超过上传大小";
exit;
}
$size=1*1024*1024;
if($file['file']['size']>$size){
echo "超过1M,禁止上传";
exit;
}
//运行上传的文件类型
$ftype=array('png','jpeg','jpg');
$name=$file['file']['name'];
$arr=explode('.',$name);
$ext=array_pop($arr);
if(!in_array($ext, $ftype)){
echo "只允许上传png jpeg jpg格式的文件";
exit;
}
date_default_timezone_set('Asia/Shanghai');
$date=date('Ymd',time());
//根据日期生成对应的上传图片目录
$path='./static/image'."/".$date;
if(!file_exists($path)){
mkdir($path);
}
$newf=time().mt_rand().".".$ext;
$imgpath=$path."/".$newf;
move_uploaded_file($file['file']['tmp_name'],$imgpath);
return $imgpath;
}