[php]代码库
/**
* 上传文件
*/
public function upload_file(){
$name=I('name');
$sku_id=I('ids');
//处理上传图片
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 3000000 ;// 设置附件上传大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->allowTypes = array('image/jpg','image/jpeg','image/pjpeg','image/png','image/gif');
$upload->rootPath = './Public/Data/Goods/';// 设置附件上传目录
$upload->savePath = ''; // 设置附件上传(子)目录
$upload->replace = true;
$upload->autoSub = false;
$upload->saveName ="".$sku_id."";
if($_FILES['photo']){
$info=$upload->uploadOne($_FILES['photo']);
if(!$info) {
// 上传错误提示错误信息
return '2000';
}
$pic_path= './Public/Data/Goods/'.$info['savepath'].$info['savename'];
}
return $pic_path;
}