Example #1
0
 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);
     }
 }
 public function update()
 {
     $upload = new \Think\Upload();
     // 实例化上传类
     $upload->maxSize = 3145728;
     // 设置附件上传大小
     $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
     // 设置附件上传类型
     $upload->rootPath = './Public/Home';
     $upload->savePath = './History/images/';
     // 设置附件上传目录
     // 上传文件
     $info = $upload->upload();
     if (!$info) {
         // 上传错误提示错误信息
         //$this->error($upload->getError());
         $pic = $_POST['oldpicname'];
     } else {
         // 上传成功
         foreach ($info as $file) {
             $pic = $file['savename'];
         }
     }
     $history = M("history");
     $_POST['history_picname'] = $pic;
     $history->create();
     if ($history->save()) {
         $this->success("修改成功", 'index');
     } else {
         $this->error("修改失败");
     }
 }
Example #3
0
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'];
    }
}
 /**
  * 模板上传控制器
  */
 public function upload()
 {
     if (!IS_POST) {
         E('无效的页面');
     }
     $upload = new \Think\Upload();
     // 实例化上传类
     $upload->maxSize = 31457280;
     // 设置附件上传大小
     // $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg','rar','zip');// 设置附件上传类型
     $upload->rootPath = './Public/';
     // 设置附件上传根目录
     $upload->savePath = '/Muban/';
     // 设置附件上传(子)目录
     // 上传文件
     $info = $upload->upload();
     //上传文件数据,包括保存地址,保存名称等。
     $data = array('suolue' => $info['suolue']['savepath'] . $info['suolue']['savename'], 'yetou' => $info['yetou']['savepath'] . $info['yetou']['savename'], 'dianzhao' => $info['dianzhao']['savepath'] . $info['dianzhao']['savename'], 'beijing' => $info['beijing']['savepath'] . $info['beijing']['savename'], 'datu' => $info['datu']['savepath'] . $info['datu']['savename'], 'orther' => $info['orther']['savepath'] . $info['orther']['savename'], 'uper' => session('name'), 'time' => time());
     $db = M('zxmb');
     $result = $db->data($data)->add();
     // echo "<pre>".print_r($result,true)."</pre>";
     if ($result) {
         $this->success('添加成功', U('/Admin/Index/index'));
     } else {
         $this->error('添加失败');
     }
 }
Example #5
0
 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 upload()
 {
     $token = I('post.token');
     $timestamp = I('post.timestamp');
     $verifyToken = md5('unique_salt' . $timestamp);
     if (!empty($_FILES) && $token == $verifyToken) {
         //上传参数配置
         $config = array('maxSize' => 3145728, 'rootPath' => './Uploads/', 'savePath' => '', 'saveName' => array('uniqid', ''), 'exts' => array('jpg', 'gif', 'png', 'jpeg'), 'autoSub' => true, 'subName' => array('date', 'Ymd'));
         $upload = new \Think\Upload($config);
         // 实例化上传类
         // 上传文件
         $info = $upload->upload();
         // dump($info);die;
         if (!$info) {
             // 上传错误提示错误信息
             // exit($upload->getError());
             $data = array('status' => 0, 'info' => $upload->getError());
         } else {
             // 上传成功
             //     			//添加水印和缩略图
             //     			$img_url=$config['rootPath'].$info['Filedata']['savepath'].$info['Filedata']['savename'];//图片地址
             //     			$img=new \Think\Image(1,$img_url);
             //     			$mark="./Public/img/hbh.png";//水印图片地址
             //     			$img->water($mark);//添加水印默认是右下角
             //     			$img->save($img_url);//保存水印后的图片
             //     			$tumb=$img->thumb(250,150);//缩略图宽250px 高150px 等比例缩放
             //     			$tumb_url=$config['rootPath'].$info['Filedata']['savepath'].'tb_'.$info['Filedata']['savename'];//缩略图地址
             //     			$img->save($tumb_url);//保存缩略图
             $data = array('savename' => $info['Filedata']['savename'], 'savepath' => $config['rootPath'] . $info['Filedata']['savepath'], 'status' => 1);
         }
         $this->ajaxReturn($data);
     }
 }
 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']);
     }
 }
 /**
  *  上传视频
  *  上传大小要更改       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;
     }
 }
 /**
  * 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 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"));
     }
 }
Example #11
0
 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("修改失败");
     }
 }
 /**
  * [处理系统配置文件修改]
  */
 public function ModSysHandle()
 {
     $upload = new \Think\Upload();
     // 实例化上传类
     $upload->rootPath = "./Public/";
     //rootPath这个路径必须手动创建
     $upload->savePath = "Logo/";
     //这一块只能设置一层目录
     $info = $upload->upload();
     if ($info) {
         // 上传成功 获取上传文件信息
         $image = new \Think\Image();
         $image->open('./Public/' . $info['face']['savepath'] . $info['face']['savename']);
         // 按照原图的比例生成一个最大为150*150的缩略图并保存为thumb.jpg
         $image->thumb(230, 45)->save('./Public/Logo/Logo.png');
     }
     $post = $_POST;
     $str = file_get_contents('Application/Common/Conf/config.php');
     //将配置文件中内容读出
     foreach ($post as $key => $val) {
         if (in_array($key, array_keys(C()))) {
             //判断键值是否存在于配置文件中
             $zz[] = "/'{$key}'\\s*.*?,\\n/i";
             $rep[] = "'{$key}' => '{$val}',\n";
         }
     }
     $str = preg_replace($zz, $rep, $str);
     //在str中匹配  然后替换
     //将修改后的文件重新写入到配置文件中
     if (file_put_contents('Application/Common/Conf/config.php', $str)) {
         //$this->success('修改成功',U('System/index'),3);
         $this->success('修改成功');
     }
 }
Example #13
0
 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;
 }
Example #14
0
 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 #15
0
 public function add()
 {
     $bp = M('Banner');
     if (IS_POST) {
         if ($_FILES['ban_url']) {
             $upload = new \Think\Upload();
             // 实例化上传类
             $upload->maxSize = 3145728;
             // 设置附件上传大小
             $upload->rootPath = './Public/';
             // 设置附件上传根目录
             $info = $upload->upload();
             $time = time();
             $nowtime = date('Y-m-d', $time);
             $url = '/Public/' . $info['ban_url']['savepath'] . $info['ban_url']['savename'];
             $arr = array('ban_name' => $_POST['ban_name'], 'ban_url' => $url, 'ban_addtime' => $nowtime);
             $result = $bp->add($arr);
             if ($result) {
                 echo "<script>alert('添加成功');window.location.href='/index.php/Admin/Photo/lis';</script>";
             } else {
                 echo "<script>alert('添加失败');window.location.href='/index.php/Admin/Photo/lis';</script>";
             }
         }
     }
     $this->display();
 }
 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 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 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 insert()
 {
     //获取pid的值
     $fid = I('post.fid');
     //创建模型
     $fit = M('fit_goods_images');
     if (!$fid) {
         $this->error('添加配件图显失败,请先选择配件名称', U('Fitimg/add'), 2);
         exit;
     }
     //上传图片进行判断,如果有图片上传,即在form表单传递过来有值,需要先上传文件后,然后再删除原来的文件
     //实例化上传类
     $upload = new \Think\Upload();
     //rootPath方法,路径必须手动创建
     $upload->rootPath = "./Public/Uploads/";
     //设置图片上传目录,只能设置一层目录
     $upload->savePath = "fit_goods_images/";
     //上传图片文件
     $info = $upload->upload();
     //整理字段img值,拼接图片路径编程规则:/Public/Uploads/goods_cate/2015-01-19/54bc80302291b.jpg
     $_POST['img'] = trim($upload->rootPath . $info['img']['savepath'] . $info['img']['savename'], '.');
     //创建数据
     // var_dump($_POST);
     $s = $fit->create();
     // var_dump($s);die;
     // 判断添加数据是否成功,并跳转重定向
     if ($fit->add()) {
         $this->success('添加配件图显成功', U('Fitimg/add', 'fid=' . $fid), 2);
     } else {
         $this->error('添加配件图显失败', U('Fitimg/add'), 2);
     }
 }
 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);
 }
 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;
 }
Example #22
0
 /**
  * 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();
     }
 }
 private function upload()
 {
     $config = array('maxSize' => 3145728, 'rootPath' => './Uploads/', 'savePath' => '', 'saveName' => 'time', 'exts' => array('jpg', 'gif', 'png', 'jpeg'), 'autoSub' => true, 'subName' => array('date', 'Ymd'));
     $upload = new \Think\Upload();
     $info = $upload->upload();
     return $info;
 }
Example #25
0
/**
 * 单文件上传
 * @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'];
    }
}
Example #26
0
 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 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));
 }
 /**
  * 文件上传
  * @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;
     }
 }
Example #30
0
 /**
  * 增加商品
  */
 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");
     }
 }