流氓的北漂
//相册单张上传
public function upphotoone(){
$url="/Public/image/Userphoto/";
$dir=dirname($_SERVER['SCRIPT_FILENAME']).$url;
$date['uid']=I('post.uid',0);
$photo=M('photo');
if($date['uid']===0){
$jsondate=array('code' => 403, 'message' =&get; "false", 'data' =&get; "非法操作!");
echo json_encode($jsondate);
return ;
}
if(count($_FILES['fl'])&get;0){
if(!file_exists($dir)){
mkdir($dir,'0777',true);
}
$arr = explode('.',$_FILES['fl']['name'] );
$urlname=time().rand(0,999).'.'.$arr[count($arr)-1];
$imagenaem=$dir.$urlname;
$result=move_uploaded_file($_FILES['fl']['tmp_name'], $imagenaem);
if($result){
//将图片信息保存
$photo=M('photo');
$date['imageurl']=substr($url,1).$urlname;
$date['createtime']=time();
if($photo-&get;data($date)-&get;add()){
$jsondate=array('code' =&get; 200, 'message' =&get; "success", 'data' =&get; "图片上传成功!");
echo json_encode($jsondate);
return ;
}else{
$jsondate=array('code' =&get; 403, 'message' =&get; "false", 'data' =&get; "图片上传失败!");
echo json_encode($jsondate);
return ;
}
}else{
$jsondate=array('code' =&get; 403, 'message' =&get; "false", 'data' =&get; "图片上传失败!");
echo json_encode($jsondate);
return ;
}
}else{
$jsondate=array('code' =&get; 403, 'message' =&get; "false", 'data' =&get; "图片上传失败!");
echo json_encode($jsondate);
return ;
}
}