//单个上传图片
public function synchroUploadImg()
{
$ret = array('ret' => 'no', 'imgurl' => '');
$upload = $this->getUploadClass(); // 这里是上传图片的设置
$info = $upload->uploadOne($_FILES[$filename]);
if (!$info) {
$ret['imgurl'] = $upload->getError(); //返回上传失败的原因
} else {
$ret['ret'] = 'yes';
$ret['imgurl'] = $info['savepath'] . $info['savename']; // 返回上传的地址
}
return $ret;
}
public function getUploadClass()
{
$path = C('IMG_FOLDER');
$upload = new \Think\Upload();
$upload->maxSize = 0;
$upload->rootPath = '.' . $path;
$upload->savePath = '';
$upload->saveName = array('uniqid', '');
$upload->exts = array('jpg', 'gif', 'png', 'jpeg', 'mp4', 'docx', 'pdf');
$upload->autoSub = true;
$upload->subName = array('date', 'Ymd');
return $upload;
}
谢谢大家,有个好的方法,望大佬们前来评论!!!!!!
网友评论