if($data['picture_input']!=''){
//判断图片是否存在
if(!file_exists('static/uploads/category/0/'.$data['picture_input'])){
return ['code'=>0,'msg'=>'类别图片丢失,请重新添加','/static/uploads/category/0/'.$data['picture_input']];
}else{
$id=$this->insertGetId($categoryData);
$date=explode('\\', $data['picture_input']);
//创建需要移动到的位置
if(!file_exists('static/uploads/category/'.$id.'/'.$date[0])){
mkdir('static/uploads/category/'.$id.'/'.$date[0].'/',0777,true);
}
$movePath='static/uploads/category/0/'.$data['picture_input'];
$savePath='static/uploads/category/'.$id.'/'.$data['picture_input'];
rename($movePath,$savePath);//移动文件
return ['code'=>1,'msg'=>'添加成功'];
}
}else{
$this->insert($categoryData);
return ['code'=>1,'msg'=>'添加成功'];
}
tp5-移动文件的位置
最新推荐文章于 2022-04-06 17:47:15 发布