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('链接修改失败'); } } }
/** * @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 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 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 image() { $data = I('post.fid'); $fileName = I('post.id'); $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->savePath = './Company/Product/'; // 设置附件上传目录 $upload->saveName = (string) session('user.id') . '_' . $fileName; $upload->saveExt = 'JPEG'; $upload->subName = ""; $upload->replace = true; $upload->hash = false; $info = $upload->upload(); if (!$info) { $msg['code'] = 0; $msg['msg'] = $upload->getError(); } else { $msg['code'] = 1; $msg['msg'] = 'chenggong'; $msg['url'] = '/Uploads/Company/Product/' . $info[$data]['savename']; } $this->ajaxReturn($msg); }
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")); } }
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 uploads() { $upload = new \Think\Upload(); $upload->maxSize = 3145728; //设置上传图片大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); //设置附件上传类型 $upload->savePath = "Photo"; //上传(子)目录 $info = $upload->upload(); //上传文件 if (!$info) { $this->error($upload->getError()); } //保存图片名 $_POST['photo_name'] = $info['photo_name']['savepath'] . $info['photo_name']['savename']; $_POST['uid'] = $_SESSION['user']['id']; //用户id //生成缩略图 $image = new \Think\Image(); $bigimage = $info['photo_name']['savepath'] . $info['photo_name']['savename']; $srcimg = $upload->rootPath . $bigimage; $image->open($srcimg); $image->thumb(250, 150, \Think\Image::IMAGE_THUMB_CENTER); $smallimage = $info['photo_name']['savepath'] . 'thumb_' . $info['photo_name']['savename']; $image->save($upload->rootPath . $smallimage); $_POST['photo_name_thumb'] = $smallimage; }
/** * swfupload 上传 */ public function swfupload() { if (IS_POST) { //上传处理类 $config = array('rootPath' => './' . C("UPLOADPATH"), 'savePath' => '', 'maxSize' => 11048576, 'saveName' => array('uniqid', ''), 'exts' => array('jpg', 'gif', 'png', 'jpeg', "txt", 'zip'), 'autoSub' => false); $upload = new \Think\Upload($config); // $info = $upload->upload(); //开始上传 if ($info) { //上传成功 //写入附件数据库信息 $first = array_shift($info); if (!empty($first['url'])) { $url = $first['url']; } else { $url = C("TMPL_PARSE_STRING.__UPLOAD__") . $first['savename']; } echo "1," . $url . "," . '1,' . $first['name']; exit; } else { //上传失败,返回错误 exit("0," . $upload->getError()); } } else { $args = I('get.args'); $argsArr = explode(',', $args); $argsStr = $argsArr[3] . '|' . $argsArr[4] . '|' . $argsArr[5] . '|' . $argsArr[6] . '|' . $argsArr[7] . '|' . $argsArr[8]; $this->assign('argsstr', $argsStr); $limit_nums = $argsArr[0] > 0 ? $argsArr[0] : '1'; $this->assign('limit_nums', $limit_nums); $this->display(':swfupload'); } }
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)); }
public function upload() { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 1003145728; // 设置附件上传大小 //$upload->exts = array('pdf', 'gif', 'jpg', 'jpeg');// 设置附件上传类型 $upload->rootPath = './Uploads/'; // 设置附件上传根目录 $upload->savePath = ''; // 设置附件上传(子)目录 // 上传文件 $info = $upload->upload(); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 获取上传文件信息 foreach ($info as $file) { echo $file['savepath'] . $file['savename']; } $Equipment = M("Equipment"); $data['serialnumber'] = $_POST["number"]; $data['name'] = $_POST["name"]; $data['status'] = $_POST["status"]; $data['owner'] = $_POST["owner"]; $data['price'] = $_POST["price"]; $data['dir'] = $file['savepath'] . $file['savename']; $Equipment->add($data); echo '<script language="javascript" type="text/javascript"> window.location.href="index.php?m=home&c=machine&a=insertshow"; alert("上传成功"); </script>'; } }
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; }
public function upload() { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('xml'); // 设置附件上传类型 $upload->rootPath = './Public/xmlFiles/'; // 设置附件上传根目录 $upload->savePath = ''; // 设置附件上传(子)目录 // 上传文件 $info = $upload->upload(); $path = null; // dump($info); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 foreach ($info as $file) { $path[$file['key']] = $file['savepath'] . $file['savename']; } $this->success('upload success!', 'xml_me.html?path1=' . $path['file1'] . '&path2=' . $path['file2']); } }
public function upload() { $upload = new \Think\Upload($this->config); // 实例化上传类 $info = $upload->upload(); $isEditor = I('post.editor', false); if (!$info) { // 上传错误提示错误信息 $data['msg'] = $upload->getError(); $data['success'] = false; $this->ajaxReturn($data); } else { // 上传成功 //$root = '/Uploads/Images/'; $root = substr($this->config['rootPath'], 1); if ($isEditor == true) { $root = '/mall' . $root; } $data['msg'] = 'upload success'; $data['success'] = true; $data['editor'] = $isEditor; foreach ($info as $key => $value) { $data['file_path'] = $root . $value['savepath'] . $value['savename']; } $this->ajaxReturn($data); } }
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']); } }
/** * 增加商品 */ public function addx() { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = './Uploads/'; // 设置附件上传根目录 $upload->savePath = ''; // 设置附件上传(子)目录 $upload->saveName = 'time'; $upload->autoSub = false; // 上传文件 $info = $upload->upload(); $Support = D("Support"); $Support->create(); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 $Support->photo = $info['photo']['savename']; $Support->add(); $this->success('发布成功', "index"); } }
public function add_img() { $product_id = I('product_id'); $upload = new \Think\Upload(); $pic_info = M('pic_info'); $upload->maxSize = 0; $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); $upload->rootPath = './Uploads/product/'; $upload->savePath = $product_id . '/'; // $upload->saveName = 'time().'_'.mt_rand()'; $upload->autoSub = false; //上传文件 $info = $upload->upload(); if (!$info) { $this->error($upload->getError()); } else { foreach ($info as $key => $file) { $file_name = UserController::img_check('./Uploads/product/' . $product_id . '/' . $file['savename']); $data['product_id'] = $product_id; $data['pic_name'] = $file_name; $data['default'] = 0; $product_result = $pic_info->add($data); } } if ($product_result) { $this->success('上传成功', '/Home/editor/editor?product_id=' . $product_id); } else { $this->error('上传失败!'); } }
public function improve() { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = './Uploads/'; // 设置附件上传根目录 $upload->savePath = ''; // 设置附件上传(子)目录 // 上传文件 $info = $upload->upload(); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 获取上传文件信息 $_POST['company_image'] = $info['company_image']['savepath'] . $info['company_image']['savename']; $_POST['contact_image'] = $info['contact_image']['savepath'] . $info['contact_image']['savename']; if (isset($info[1])) { $_POST['contact_image'] = $info[1]['savename']; } $_POST['status'] = 4; $this->update(); } }
/** * swfupload 上传 */ public function swfupload() { if (IS_POST) { //上传处理类 $config = array('rootPath' => './' . C("UPLOADPATH"), 'savePath' => '', 'maxSize' => 11048576, 'saveName' => array('uniqid', ''), 'exts' => array('jpg', 'gif', 'png', 'jpeg', "txt", 'zip'), 'autoSub' => false); $upload = new \Think\Upload($config); // $info = $upload->upload(); //开始上传 if ($info) { //上传成功 //写入附件数据库信息 $first = array_shift($info); if (!empty($first['url'])) { $url = $first['url']; } else { $url = C("TMPL_PARSE_STRING.__UPLOAD__") . $first['savename']; } echo "1," . $url . "," . '1,' . $first['name']; exit; } else { //上传失败,返回错误 exit("0," . $upload->getError()); } } else { $this->display(':swfupload'); } }
public function update() { $id = I('get.id'); $FriendLink = DD('FriendLink'); $link = $FriendLink->selectbyid($id); if (IS_POST) { $data = I('post.'); if ($_FILES) { if ($_FILES['image']['error'] == 0) { $upload = new \Think\Upload(); $upload->maxSize = 3292200; $upload->allowExts = explode(',', 'jpg,gif,png,jpeg'); $upload->savePath = 'link/'; $info = $upload->upload(); if (!$info) { $this->error($upload->getError()); } else { $up_root = str_replace('./', '', $upload->rootPath); $data['image_url'] = $up_root . $info['image']['savepath'] . $info['image']['savename']; @unlink($result['image_url']); } } } $result = $FriendLink->update($id, $data); if ($result) { $this->success('修改成功'); } else { $this->error('发生错误,请重试'); } } else { $this->assign('link', $link); $this->display(); } }
public function add() { $upload = new \Think\Upload(); $upload->maxSize = 3145728; // 设置附件上传大小 $upload->allowExts = array('jpg', 'png', 'jpeg'); // 设置附件上传类型 $upload->autoSub = false; $upload->rootPath = "./Public/"; // 设置附件上传目录 $upload->savePath = "images/"; // 设置附件上传目 if (!($arr = $upload->upload())) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 获取上传文件信息 $data['goods_pic'] = $arr['goods_img']['savepath'] . $arr['goods_img']['savename']; $data['goods_id'] = $_POST['goods_id']; $data['goods_name'] = $_POST['goods_name']; $data['goods_price'] = $_POST['goods_price']; $data['category_id'] = $_POST['category_id']; $m = M("goods"); $arr = $m->add($data); $this->success('上传成功!'); } // $this -> redirect("Category/show"); }
public function render() { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('txt'); // 设置附件上传类型 $upload->rootPath = './Uploads/'; // 设置附件上传根目录 $upload->savePath = ''; // 设置附件上传(子)目录 // 上传文件 $info = $upload->upload(); /* info具体信息 * array(1) { ["uploadfile"]=> array(9) { ["name"]=> string(22) "鏂板缓鏂囨湰鏂囨。.txt" ["type"]=> string(10) "text/plain" ["size"]=> int(12) ["key"]=> string(10) "uploadfile" ["ext"]=> string(3) "txt" ["md5"]=> string(32) "89403e405bbb916ea8627a445847f50a" ["sha1"]=> string(40) "47c402148721956af6a75f66d57160a237cdf303" ["savename"]=> string(17) "54058a891ac2e.txt" ["savepath"]=> string(11) "2014-09-02/" } } * */ var_dump($info); die(''); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 $this->success('上传成功!'); } $this->display(); }
public function publish() { //$setting=C('UPLOAD_SITEIMG_QINIU'); $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 2005728; // 设置附件上传大小 $upload->exts = array('jpg', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = './Uploads/'; // 设置附件上传根目录 $upload->savePath = ''; // 设置附件上传(子)目录 // 上传文件 $info = $upload->upload(); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } $article = M('Article'); $data['article_title'] = I('post.publishTitle'); $data['publish_time'] = date("YmdHis"); $data['article_content'] = I('post.content'); $data['img_url'] = './Uploads/' . $info['photo']['savepath'] . $info['photo']['savename']; //$data['img_url'] =$info['photo']['url']; $data['status'] = 1; $data['editor_name'] = session('uname'); $data['cate_name'] = I('post.Cate'); $data['cname'] = I('post.cate'); if ($article->add($data)) { $this->success('发布成功', __ROOT__ . '/index.php', 2); } else { $this->error($user->getError()); } }
public function doAuth() { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->savePath = './Company/Auth/'; // 设置附件上传目录 $upload->saveName = (string) session('user.id'); $upload->saveExt = 'JPEG'; $upload->subName = ""; $upload->replace = true; $upload->hash = false; $info = $upload->upload(); if (!$info) { $msg['code'] = 0; $msg['msg'] = $upload->getError(); } else { $save['id'] = $this->uid; $save['state'] = 3; $this->comObj->save($save); $msg['code'] = 1; $msg['url'] = U('Home/CompanyAuth/authSuccess'); $msg['msg'] = '操作成功'; } $this->ajaxReturn($msg); }
function uploadpdf() { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('pdf'); // 设置附件上传类型 $upload->rootPath = './Uploads/'; // 设置附件上传根目录 $upload->savePath = ''; // 设置附件上传(子)目录 $upload->autoSub = true; $upload->subName = array('date', 'Ymd'); $info = $upload->upload(); if (!$info) { // 上传错误提示错误信息 $data['success'] = false; $data['info'] = $upload->getError(); } else { // 上传成功 获取上传文件信息 $data['success'] = true; foreach ($info as $file) { $data['info'][] = 'http://' . $_SERVER['HTTP_HOST'] . '/Uploads/' . $file['savepath'] . $file['savename']; } } return $data; }
public function add() { $upload = new \Think\Upload(); $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = 'Public/'; $upload->savePath = 'Uploads/'; $info = $upload->upload(); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 获取上传文件信息 $slide_pic = $info[0]['savepath'] . $info[0]['savename']; $slide_bg = $info[1]['savepath'] . $info[1]['savename']; } $slide = M("Slide"); if ($slide->create()) { $slide->slide_time = strtotime($_POST['slide_time']); $slide->slide_pic = $slide_pic; $slide->slide_bg = $slide_bg; if ($slide->add()) { $this->success("添加成功!", U("slidelist")); } else { $this->error("添加失败!", U("addslide")); } } else { $this->error("添加失败!", U("addslide")); } }
public function update() { if ($_FILES['pic']['name']) { $upload = new \Think\Upload(); $upload->maxSize = 1024000000; $upload->autoSub = false; $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); $upload->rootPath = "Public/"; $upload->savePath = '/Uploads/links/'; $info = $upload->upload(); if (!$info) { $this->error($upload->getError()); } else { $path = "Public/" . $info['pic']['savepath']; $name = $info['pic']['savename']; $file = $path . $name; $image = new \Think\Image(); $image->open($file); $image->thumb(100, 100)->save($path . "s_" . $name); unlink($file); $_POST['linklogo'] = $name; } } $links = M("links"); if ($links->create()) { if ($links->save()) { $this->success("修改成功!", "index"); } else { $this->error("修改失败!"); } } }
public function update() { if ($_FILES['pic']) { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); //设置附件上传类型 $upload->rootPath = './Public/'; // 设置附件上传根目录 $upload->savePath = './Uploads/pic/'; // 设置附件上传目录 $upload->autoSub = false; //关闭子目录生成 $info = $upload->upload(); if (!$info) { echo $this->error($upload->getError()); } else { //上传图片成功 $file = $info['pic']; $_POST['bigpic'] = $file['savename']; } } $mod = M('guest'); if ($mod->create()) { $mod->save(); $this->success("修改成功"); } else { $this->success("修改失败"); } }
/** * 文件上传 * @param array $files 要上传的文件列表(通常是$_FILES数组) * @param array $setting 文件上传配置 * @param string $driver 上传驱动名称 * @param array $config 上传驱动配置 * @return array 文件上传成功后的信息 */ public function upload($files, $setting, $driver = 'Local', $config = null) { /* 上传文件 */ $setting['callback'] = array($this, 'isFile'); $Upload = new \Think\Upload($setting, $driver, $config); $info = $Upload->upload($files); /* 设置文件保存位置 */ $this->_auto[] = array('location', 'Ftp' === $driver ? 1 : 0, self::MODEL_INSERT); if ($info) { //文件上传成功,记录文件信息 foreach ($info as $key => &$value) { /* 已经存在文件记录 */ if (isset($value['id']) && is_numeric($value['id'])) { $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename']; //在模板里的url路径 continue; } $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename']; //在模板里的url路径 /* 记录文件信息 */ if ($this->create($value) && ($id = $this->add())) { $value['id'] = $id; } else { //TODO: 文件上传成功,但是记录文件信息失败,需记录日志 unset($info[$key]); } } return $info; //文件上传成功 } else { $this->error = $Upload->getError(); return false; } }
/** * 上传视频 * 上传大小要更改 php.ini * post_max_size 默认为8M * upload_max_filesize 默认为2M * 默认这两 */ function uploadImg() { $upload = new \Think\Upload(); $upload->maxSize = 20 * 1024 * 1024; // 设置附件上传大小 (3M) $upload->exts = array('jpg', 'gif', 'png', 'jpeg', 'mp4', 'mov', 'avi'); // 设置附件上传类型 $upload->savePath = '/Uploads/'; // 设置附件上传目录 $upload->rootPath = './Public'; $upload->saveName = 'GUID'; // 根目录 //echo ini_get('upload_max_filesize'); // is_dir($upload->rootPath) or mkdir($upload->rootPath,0777,true); $info = $upload->upload(); if (!$info) { // 上传错误提示错误信息 $this->vendor(0, $upload->getError()); } else { // 上传成功 获取上传文件信息 foreach ($info as $k => $file) { $picUrlArr[$k] = ltrim($upload->rootPath, '.') . $file['savepath'] . $file['savename']; } $this->vendor(1, 'success', array('pic_url' => $picUrlArr)); exit; } }