public function index() { $m_setting = D('Setting'); if (chkSubmit()) { dumps($_FILES); $update = array(); $update['site_name'] = $this->getString('post.site_name'); //$update['site_logo'] = $this->getString('post.site_logo'); //$update['member_face'] = $this->getString('post.member_face'); $update['site_seo'] = $this->getString('post.site_seo'); $update['site_email'] = $this->getString('post.site_email'); $update['upload_size_limit'] = $this->getInt('post.upload_size_limit') * 1024; $update['site_phone'] = $this->getString('post.site_phone'); $update['site_status'] = $this->getString('post.site_status'); $update['closed_reason'] = $this->getString('post.closed_reasons'); //logo if ($_FILES) { $upload = new \Think\Upload(); // 实例化上传类 $upload->rootPath = C('UPIMG_PATH') . '/'; // 设置附件上传根目录 $upload->savePath = ''; // 设置附件上传(子)目录 if ($_FILES['site_logo']['name']) { //logo $result = $upload->uploadOne($_FILES['site_logo']); if ($result) { $path = $result['savepath'] . $result['savename']; $update['site_logo'] = $path; } else { $this->error($upload->getError()); } } if ($_FILES['member_face']['name']) { //member_face $result = $upload->uploadOne($_FILES['member_face']); if ($result) { $path = $result['savepath'] . $result['savename']; $update['member_face'] = $path; } else { $this->error($upload->getError()); } } } $res = $m_setting->updateAll($update); if ($res) { $this->success('更新成功'); } else { $this->error('更新失败'); } } $setting_list = $m_setting->getSettingList(array()); $this->assign('setting', $setting_list); $this->display('html/setting'); }
public function submitSignup() { $upload = new \Think\Upload(C("UPLOAD_USER_PICS_CONFIG")); $info = $upload->uploadOne($_FILES['upic']); if (!$info) { $this->error($upload->getError()); } else { dump($info); $image = new \Think\Image(); $image->open(C("UPLOAD_USER_PICS_CONFIG.rootPath") . $info['savepath'] . $info['savename']); $thumb_url = C("UPLOAD_USER_PICS_CONFIG.rootPath") . $info['savepath'] . 'thumb_' . $info['savename']; $image->thumb(C("THUMB_USER_PIC_WIDTH"), C("THUMB_USER_PIC_HEIGHT"))->save($thumb_url); $_POST['upic'] = $info['savename']; } $_POST['upwd'] = I("upwd", "", md5); if (M("User")->create()) { $uid = M("User")->add(); if ($uid) { session("uid", $uid); session('uname', I('uname')); $this->redirect("Index/index"); } } $this->error("注册失败"); }
/** * 单文件上传 * @param array * @return string */ function upload_one($param) { $upload = new \Think\Upload(); $upload->maxSize = 2097152; //字节 1KB=1024字节 默认为2M if (isset($param['exts'])) { $upload->exts = $param['exts']; } else { $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); } $upload->savePath = $param['savePath']; //保存路径 相对路径 $upload->subName = $param['subName']; //子目录 $upload->saveName = $param['saveName']; //保存名称 $upload->saveExt = $param['saveExt']; //保存后缀 $upload->replace = true; //存在同名的文件 覆盖 $info = $upload->uploadOne($param['files']); if (!$info) { return 'error'; } else { return $info['savepath'] . $info['savename']; } }
function upload_one_thumb($param, $w = 680, $h = 250) { $upload = new \Think\Upload(); $upload->maxSize = 2097152; //字节 1KB=1024字节 默认为2M $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); $upload->savePath = $param['savePath']; //保存路径 相对路径 $upload->subName = $param['subName']; //子目录 $upload->saveName = $param['saveName']; //保存名称 $upload->saveExt = $param['saveExt']; //保存后缀 $upload->replace = true; //存在同名的文件 覆盖 $info = $upload->uploadOne($param['files']); if (!$info) { return 'error'; } else { $img_src = './Uploads/' . $info['savepath'] . $info['savename']; $image = new \Think\Image(); $image->open($img_src); //将图片裁剪为680X250并保存为 $new_img_src = './Uploads/' . $info['savepath'] . 'thumb_' . $info['savename']; $image->crop($w, $h)->save($new_img_src); return $info['savepath'] . $info['savename']; //return $info['savepath'].'thumb_'.$info['savename']; } }
/** * 上传文件 * @param unknown $file * @param string $rootPath * @param number $maxSize * @param unknown $exts * @param string $randomSaveName * @return stdClass */ function upload($file, $maxSize = 3145728, $exts = array(), $rootPath = '', $randomSaveName = true, $saveName = "") { if (empty($rootPath)) { $rootPath = C('IMAGE_PATH'); } $upload = new \Think\Upload(); $upload->maxSize = $maxSize; if (!$randomSaveName) { $saveName = iconv('utf-8', 'gbk', $saveName); $upload->saveName = $saveName; } $upload->exts = $exts; $upload->rootPath = $rootPath; $info = $upload->uploadOne($file); $res = new stdClass(); if (!$info) { $res->success = false; $res->message = $upload->getError(); $res->filePath = ""; } else { $info['savename'] = iconv('gbk', 'utf-8', $info['savename']); $res->success = true; $res->message = "上传成功"; $res->filePath = str_replace("./", "", $rootPath) . $info['savepath'] . $info['savename']; $res->savename = $info['savename']; } return $res; }
public function upload() { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 133145728; // 设置附件上传大小 $upload->exts = array('jpg', 'png'); // 设置附件上传类型 $upload->rootPath = './Public/Uploads/Video/'; // 设置附件上传目录 ini_set('post_max_size', '1000M'); //$upload->imageClassPath = '@.ORG.Image'; //设置需要生成缩略图的文件后缀 $info = $upload->uploadOne($_FILES['photo1']); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 获取上传文件信息 $this->success('上传成功!'); } $data['id'] = $_POST['id']; $data['name'] = $info['savename']; $data['create_time'] = time(); $data['path'] = $info['savepath']; $data['link'] = $_POST['link']; $data['lable'] = $_POST['lable']; $pic = M("videonews"); if ($pic->save($data)) { $this->success('上传成功!'); } else { $this->fail('上传失败!'); } }
public function save() { $Link = D('link'); $data = $Link->create(); if ($Link->type == 'file' && $_FILES['android']['error'] != 4) { C('DB_PREFIX', 'rou_'); $savePath = M('website')->getFieldByid($Link->webid, 'filename'); $config = array('exts' => 'apk', 'rootPath' => '.' . $savePath . '/resources/'); $Upload = new \Think\Upload($config); $info = $Upload->uploadOne($_FILES['android']); if ($Upload->getError()) { $this->error($Upload->getError()); } $Link->android = $savePath . '/resources/' . $info['savepath'] . $info['savename']; } if ($Link->id) { //修改 if ($Link->save()) { updateApi($data['webid'], 'getLink', $data['id']); $this->success('链接修改成功'); } else { $this->error('链接修改失败'); } } else { //添加 if ($Link->add()) { updateApi($data['webid'], 'getLink', $Link->getLastInsId()); $this->success('链接修改成功'); } else { $this->error('链接修改失败'); } } }
public function upload() { $uid = I('post.uid'); // 上传标识 if (empty($uid)) { $return['error'] = 1; $return['message'] = '没有登录不允许上传'; exit(json_encode($return)); } /* 返回标准数据 */ $return = array('error' => 0); $dir = I('get.dir'); // 上传类型image、flash、media、file // 上传配置 $ext_arr = array('image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'), 'flash' => array('swf', 'flv'), 'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'), 'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2')); $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = $ext_arr[$dir]; // 设置附件上传类型 $upload->rootPath = './Uploads/'; $upload->savePath = $uid . '/' . $dir . '/'; $info = $upload->uploadOne($_FILES['imgFile']); if ($info) { $return['url'] = $upload->rootPath . $info['savepath'] . $info['savename']; } else { $return['error'] = 1; $return['message'] = $upload->getError(); } exit(json_encode($return)); }
protected function upload_file($username, $fileNameInHTML, $isOri) { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 if ($isOri) { $upload->exts = array('bmp'); } // 设置附件上传类型 $upload->rootPath = "Public"; $upload->savePath = "/users_pic/{$username}/rec/"; // 设置附件上传目录 $upload->saveName = ''; // 设置上传的文件名为原文件名 $upload->autoSub = false; // 不设置子文件夹(若为true, 则默认还有个时间命名规则的子文件夹) $info = $upload->uploadOne($_FILES[$fileNameInHTML]); if (!$info) { //上次嵌入文件失败的时候,会删除之前上传的OriPhoto //不过由于每次上次的嵌入文件都会被删除,所以似乎不糊发生这种情况。(只可能是上传的嵌入文件是在太大了) if ($isOri == false) { $this->deleteUserFile($username, $_FILES["OriPhoto"]["name"], true); } $this->error($upload->getError()); } return $info; }
/** * 编辑器图片上传 * * @return json */ public function keditor_uploadAct() { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 314572800; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $dir = I('get.dir'); $upload->rootPath = './'; // 保存根路径 $upload->savePath = 'data/keditor/' . $dir . '/' . date('Y-m') . '/'; // 创建目录 check_dir($upload->savePath); // 执行上传 if (!($info = $upload->uploadOne($_FILES['imgFile'], $upload->savePath))) { // 上传错误提示错误信息 echo json_encode(array('error' => 1, 'message' => "1" . $upload->getError())); } else { // 上传成功 获取上传文件信息 $fileUrl = $info['savepath'] . $info['savename']; $fullPath = __BASE__ . $fileUrl; echo json_encode(array('error' => 0, 'url' => $fullPath)); } exit; }
public function upload() { if (!session('?admin')) { $this->redirect('Main/index'); } if (session('right') != 1) { $this->error('访问无权限'); } header("Content-Type:text/html;charset=utf-8"); $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('xls', 'xlsx'); // 设置附件上传类 $upload->savePath = '/'; // 设置附件上传目录 // 上传文件 $info = $upload->uploadOne($_FILES['excelData']); $filename = './Uploads' . $info['savepath'] . $info['savename']; $exts = $info['ext']; //print_r($info);exit; if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 $this->goods_import($filename, $exts); } }
public function insert() { $art = D('Article'); $_POST['uid'] = 1; $_POST['addtime'] = time(); //$content = htmlspecialchars($_POST['content'], ENT_QUOTES); $_POST['content'] = htmlspecialchars($_POST['content'], ENT_QUOTES); $new_id = D('Article')->add($_POST); if (!empty($_FILES)) { $config = array('rootPath' => './Public/', 'savePath' => 'Uploads/'); $upload = new \Think\Upload($config); $res = $upload->uploadOne($_FILES['image']); if (!$res) { show_bug($upload->getError()); } $image = $res['savepath'] . $res['savename']; } else { $image = ''; } $_POST['img'] = $image; //print_r($_POST); // Array ( [tit] => 测试文件 [content] => 这是一个测试文件 [addtime] => 1434072175 ) //[title] => [pid] => 329 [content] => [uid] => 1 [addtime] => 1434192227 [img] => sijiosj ) $sql = "update shop_article set img='{$image}' where id={$new_id}"; $res = $art->execute($sql); //$art -> create(); //$result = $art -> add($_POST); if ($res) { $this->assign('mess', '添加权限成功'); $this->display('list'); } else { $this->assign('mess', '添加权限失败'); $this->display('list'); } }
public function upload() { $config = array('maxSize' => 3145728, 'savePath' => './Public/Upload/Image/', 'saveName' => array('uniqid', ''), 'exts' => array('jpg', 'gif', 'png', 'jpeg'), 'autoSub' => true, 'subName' => array('date', 'Ymd')); $upload = new \Think\Upload($config); // 实例化上传类 $info = $upload->uploadOne($_FILES['image']); //$filename=$_FILES['photo']['name']; //echo $filename; //$filename=iconv("utf-8","gbk",$filename); $returnData = null; if (!$info) { // 上传错误提示错误信息 } else { // 上传成功 $image = M('image'); $data['image_name'] = $_POST['imageName']; $data['savename'] = $info['savename']; $data['path'] = $info['savepath']; $data['dept_id'] = $_POST['deptId']; $data['floor_id'] = $_POST['floorId']; $image->create($data); $image->add(); } $this->redirect('Image/listImage'); }
public function upload() { $x1 = I("x1"); $y1 = I("y1"); $upload = new \Think\Upload(); $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = 'Public/'; $upload->savePath = 'Uploads/'; $info = $upload->uploadOne($_FILES['member_pic']); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 获取上传文件信息 $member_pic = $info['savepath'] . $info['savename']; } $member_p = "./Public/" . $info['savepath'] . $info['savename']; $image = new \Think\Image(); $image->open($member_p); $image->crop(128, 128, $x1, $y1)->save($member_p); $memberdetail = M("Memberdetail"); if ($memberdetail->create()) { $memberdetail->member_pic = $member_pic; $memberdetail->save(); $_SESSION['member_pic'] = $member_pic; $this->success("头像修改成功!", U("avatar")); } else { $this->error("头像修改失败!", U("avatar")); } }
protected function UploadFile() { $filename = self::$config['filename']; if (!empty($_FILES[$filename]['name'])) { $file_types = explode(".", $_FILES[$filename]['name']); $file_type = $file_types[count($file_types) - 1]; /*判别是不是.xls文件,判别是不是excel文件*/ if (!in_array(strtolower($file_type), self::$config['filetype'])) { exit('您上传的不是Excel文件,重新上传!'); } /*设置上传路径*/ //实例化上传类 $config = array('maxSize' => 3145728, 'rootPath' => self::$config['rootpath'], 'savePath' => self::$config['savepath'], 'saveName' => array('uniqid', time()), 'exts' => self::$config['filetype'], 'autoSub' => true, 'subName' => array('date', 'Ym'), 'hash' => true); $upload = new \Think\Upload($config); //开始上传 $info = $upload->uploadOne($_FILES[$filename]); //上传错误时 if (!$info) { exit($upload->getError()); } $rootpath = ltrim($config['rootPath'], '.'); $full_path = $rootpath . $info['savepath'] . $info['savename']; return array('filepath' => $full_path, 'filename' => $info['savename']); } }
/** * @example 视频添加 */ public function vadioAdd() { if (IS_POST) { $Apk = D('vadio'); $Apk->create(); $webid = $Apk->webid; $config = array('exts' => 'mp4', 'rootPath' => './', 'maxSize' => 20 * 1024 * 1024, 'subName' => array(), 'savePath' => I('post.path', '')); $Upload = new \Think\Upload($config); $info = $Upload->uploadOne($_FILES['video']); if ($Upload->getError()) { $this->error($Upload->getError()); } $Apk->img = $this->getFilePath('path', 'filename'); $Apk->url = $info['savepath'] . '/' . $info['savename']; if (!$Apk->add()) { $this->error('视频上传失败'); } $insID = $Apk->getLastInsId(); $this->updateApi($webid, 'getVadio', $insID); $this->success('添加成功'); } else { $webid = I('get.webid', ''); $cate = $this->Cate->where(array('webid' => $webid, 'type' => 'video'))->select(); $web = M('website')->getById($webid); $filepath = urlencode(str_replace('/', '.', $web['filename'] . '/reource')); $this->assign('filepath', $filepath); $this->assign('cate', $cate); $this->Public->showHeader(); $this->display('VadioAdd'); $this->Public->showFooter(); } }
public function uploadHead() { if ($_SERVER['HTTP_REFERER'] == NULL) { die("<meta charset='utf-8'><h1>非法访问</h1>"); } //防止浏览器地址访问 $tokenName = C('TOKEN_NAME', null, 'token'); if (Behavior\CheckIslogin::checkIsUser() & IS_POST & I('post.tokenforHead') == $_SESSION[$tokenName][md5('forHead')]) { //校验token成功后,清除 unset($_SESSION[$tokenName][md5('forHead')]); $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 204800; // 设置附件上传大小 $upload->exts = array('jpg', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = './Public/Upload/'; // 设置附件上传根目录 $upload->autoSub = FALSE; $upload->savePath = ''; // 设置附件上传(子)目录 // 上传单个文件 $info = $upload->uploadOne($_FILES['photo']); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 获取上传文件信息 /*$image = new \Think\Image(); $image->open('./Public/Upload/' .$info['savename']); // 判断图像大小之后,再决定是否裁剪 $image->thumb(200,200,\Think\Image::IMAGE_THUMB_CENTER)-> save('./Public/Upload/userHead/thumb/thumb'.$info['savename']); */ $resumehead = '/Upload/' . $info['savename']; $Resume = M("Resume"); // 实例化Resume对象 // 要修改的数据对象属性赋值 $condition['oid'] = md5(session('uid')); $Resume->create($condition); if (!$Resume->where($condition)->find()) { //如果没有找到简历就创建 $Resume->head = $resumehead; $Resume->name = session('name'); $Resume->tel = session('tel'); $Resume->email = session('email'); $Resume->add(); $this->success('上传成功', U('/Admin/Index/resumeUpdate')); } else { $Resume->head = $resumehead; $Resume->where($condition)->save(); $this->success('上传成功', U('/Admin/Index/resumeUpdate')); } } } else { $this->error('超时,请刷新页面'); } }
public function onAdd() { if (!empty($_FILES)) { /*实例化上传类 方法1 $upload = new \Think\Upload();// 实例化上传类 $upload->maxSize = 3145728 ;// 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型 $upload->rootPath = './Public/upload/';//上传文件 的根目录 $upload->savePath = 'link/'; // 设置附件上传目录 $upload->saveName = array('uniqfile','');//上传文件命名规则,[0]-函数名,[1]-参数,多个参数使用数组 $upload->autoSub = false;//自动子目录保存文件 */ //实例化上传类 方法2 $config = array(); //初始化参数数组 $config['maxSize'] = 3145728; // 设置附件上传大小 $config['exts'] = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $config['rootPath'] = './Public/upload/'; //上传文件 的根目录 $config['savePath'] = 'link/'; // 设置附件上传目录 $config['saveName'] = array('uniqfile', ''); //上传文件命名规则,[0]-函数名,[1]-参数,多个参数使用数组 $config['autoSub'] = false; //自动子目录保存文件 $upload = new \Think\Upload($config); // 实例化上传类 // 上传单个文件 $info = $upload->uploadOne($_FILES['linkpic']); //dump($info);exit; if ($info) { // 上传成功 将获取文件名,更新数据库和session $data['logo'] = $info['savename']; $data['linkname'] = I("post.linkname"); $data['linkaddres'] = I("post.linkaddress"); $data['content'] = I("post.content"); $data['linkip'] = get_client_ip(); //申请该友情链接的用户ip $sql = D("Friendlink"); $rs = $sql->data($data)->add($data); // dump($rs);exit; if ($rs) { $this->success("Add Sucess"); } else { $this->error("Add Failure"); } } else { $this->error('File Upload Failure'); } } else { $this->error("Please choose the file you want to upload"); } }
public function doadd() { //分享企业的头部图片上传 $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); //设置附件上传类型 $upload->savePath = './Public/Uploads/'; // 设置附件上传目录 //dump($_FILES); //exit; $info1 = $upload->uploadOne($_FILES['img']); $info2 = $upload->uploadOne($_FILES['img_big']); //dump($info1); //dump($info2); //exit; $path1 = $info1['savepath'] . $info1['savename']; $path2 = $info2['savepath'] . $info2['savename']; // dump($path1); //dump($path2); //exit; //dump($path); if (!$info1 || !$info2) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 //echo $path; } //写入分享表 $name = $_POST['name']; $intro = $_POST['intro']; $color = $_POST['color']; //$sql="insert into ju_share(`name`,`img`,`img_big`,`color`,`intro`) values('$name','$path1','$path2','$color','$intro')"; //dump($sql); //exit; $model = M(); $model->execute("insert into ju_share(`name`,`img`,`img_big`,`color`,`intro`) values('{$name}','{$path1}','{$path2}','{$color}','{$intro}')"); $this->redirect('index'); }
public function i2Data() { $config = array('rootPath' => './Uploads/Train/data2/', 'exts' => '', 'saveName' => $_FILES['fw']['name'] . '_' . time() . '_' . uniqid()); $Upload = new \Think\Upload($config); $Upload->uploadOne($_FILES['fw']); if ($Upload->getError()) { echo $Upload->getError(); exit('false'); } exit('true'); }
public function imageUploadOne($img) { $config = array('rootPath' => './Public/', 'savePath' => 'Uploads/'); $upload = new \Think\Upload($config); $res = $upload->uploadOne($img['image']); if (!$res) { // 输出错误信息 } $image = $res['savepath'] . $res['savename']; return $image; }
public function upload() { $file = $_FILES['file']; $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 2 * 1024 * 1024; $upload->rootPath = './Uploads/'; // 设置附件上传根目录 $upload->savePath = 'thumb/'; // 设置附件上传(子)目录 $info = $upload->uploadOne($file); exit(json_encode($info)); }
public function complete() { //dump($_SESSION); $id = $_SESSION['home']['id']; /*要看session那边怎么写的*/ if (IS_POST) { //现将此user所有的头像封面都变为0 $model = M(); $model->execute("update ju_touimg set `is_face`='0' where `user_id`='{$id}'"); /*上传头像*/ $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); //设置附件上传类型 $upload->savePath = './Public/Uploads/'; // 设置附件上传目录 $info = $upload->uploadOne($_FILES['name']); $path = $info['savepath'] . $info['savename']; if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } //插入上传的图片到头像表,并把它的封面设为1 $model->execute("insert into ju_touimg(`name`,`is_face`,`user_id`) values('{$path}','1','{$id}')"); } //页面资料修改 if (IS_GET) { D('User')->save($_GET); } //页面资料显示 $user = D('User'); $map1['id'] = $id; $userlist = $user->where($map1)->select(); $userlist = $userlist['0']; $_SESSION['home'] = $userlist; $this->assign('list', $userlist); //$this->display(); //页面头像显示 $touimg = D('Touimg'); $map2['user_id'] = $id; $map2['is_face'] = '1'; $img = $touimg->where($map2)->field('id,name')->select(); //dump($img); $img = $img['0']; $_SESSION['home']['img'] = $img['name']; $this->assign('img', $img); $this->display(); }
public function upload($file) { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = './Uploads/incubatorpic/'; // 设置附件上传根目录 // 上传单个文件 $info = $upload->uploadOne($file); return $info; }
public function add() { //$Category = D('Category'); if (IS_POST) { //分享企业的头部图片上传 $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); //设置附件上传类型 $upload->savePath = './Public/Category/'; // 设置附件上传目录 //exit; $info = $upload->uploadOne($_FILES['tag-img']); $path = $info['savepath'] . $info['savename']; if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { } //写入分享表 $data['name'] = $_POST['name']; $data['pid'] = $_POST['pid']; $data['path'] = $_POST['path']; //exit; $data['tag-img'] = $path; $data['content'] = $_POST['content']; //dump($data); //exit; $Category = D('Category'); //实例化Category对象 $result = $Category->add($data); if ($result) { $insertId = $result; if ($insertId > 0) { $this->redirect('Category/index'); } } } else { // 如果是点击添加一级分类,这种情况,是不会有get传递 pid和path过来的。所以此时的pid 0 path 0, // 如果用户是从分类列表点击添加子类过来的,这种情况就会有$_GET['pid']和$_GET['path']存在 $pid = empty($_GET['pid']) ? 0 : $_GET['pid']; $path = empty($_GET['path']) ? '0,' : $_GET['path'] . $pid . ','; $list = array('pid' => $pid, 'path' => $path); $this->assign($list); $this->display(); } }
public function upload($file, $filepath) { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = './Uploads/' . $filepath . '/'; // 设置附件上传根目录 // 上传单个文件 $info = $upload->uploadOne($file); //dump($upload->getError()); //错误信息 return $info; }
/** * 阿里云Oss上传图片 * @param _FILE $content 文件控件 * @return string $filepath 文件路径 */ function UploadBeforeOss($content) { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = './Uploads/'; // 设置附件上传根目录 // 上传单个文件 $info = $upload->uploadOne($content); $filepath = './Uploads/' . $info['savepath'] . $info['savename']; return $filepath; }
public function meituupload() { $upload = new \Think\Upload(); $upload->maxSize = C('UPLOAD_FILE_SIZE'); $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); $data = array(); $info = $upload->uploadOne($_FILES['pic']); if (!$info) { $data = array('msg' => 0, "msgbox" => $upload->getError()); } else { @unlink('.' . $_POST["id"]); $data = array('msg' => 1, "msgbox" => '/uploads/' . $info['savepath'] . $info['savename']); } echo json_encode($data); }
public function save() { $Mmclick = M('mmclick'); $config = array('exts' => 'jpg,png', 'rootPath' => './Uploads/mmclick/'); $Upload = new \Think\Upload($config); $info = $Upload->uploadOne($_FILES['image']); if ($Upload->getError()) { $this->error($Upload->getError()); } $data = array('image' => $info['savepath'] . $info['savename'], 'create_time' => time()); $result = $Mmclick->add($data); if ($result) { $this->success('修改成功'); } else { $this->error('修改失败'); } }
public function add() { if (IS_POST) { //品牌入库 $data['brand_name'] = I("brand_name"); $data['url'] = I("url"); $data['logo'] = I("logo"); $data['brand_desc'] = I("brand_desc"); $data['sort_order'] = I("sort_order"); $data['is_show'] = I("is_show"); if ($_FILES['logo']['tmp_name'] != '') { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = "./"; //注意,一定要设置这个 $upload->savePath = './Public/Uploads/'; // 设置附件上传目录 $info = $upload->uploadOne($_FILES['logo']); if ($info) { $data['logo'] = $info['savepath'] . $info['savename']; } else { $this->error($upload->getError()); } } //使用自定义模型用D方法 $brand = D('brand'); //使用create方法表示用自动验证 if ($brand->create($data)) { //验证通过后才插入数据 if ($brand->add()) { $this->success('添加品牌成功!', U('Brand'), 1); } else { $this->error("添加失败!"); } } else { $this->error($brand->getError()); } } else { $this->display(); } }