public function uploadImg()
 {
     $path = I('path');
     $file_name = I('file_name');
     $rootPath = __REAL_APP_ROOT__ . "/Public/upload/lcqd/";
     if (!is_dir(__REAL_APP_ROOT__ . "/Public/upload/")) {
         mkdir(__REAL_APP_ROOT__ . "/Public/upload/", 0777);
         if (!is_dir(__REAL_APP_ROOT__ . "/Public/upload/lcqd/")) {
             mkdir(__REAL_APP_ROOT__ . "/Public/upload/lcqd/", 0777);
         }
     }
     $config = array('exts' => array('png', 'gif', 'jpg', 'jpeg'), 'rootPath' => $rootPath, 'saveName' => $file_name, 'subName' => '', 'replace' => true, 'callback' => true);
     $upload = new Upload($config);
     $info = $upload->upload();
     if (!$info) {
         $this->crmError($upload->getError());
     } else {
         $data['lcqd_img_name'] = $info['file']['savename'];
         $product = M('Product');
         $where = array('productcode' => $file_name);
         $res = $product->where($where)->save($data);
         if ($res) {
             $this->crmSuccess($info['saveName'] . '上传成功');
         } else {
             $this->crmError('产品信息更新失败');
         }
     }
 }
Example #2
0
 public function introHandle()
 {
     $upload = new \Think\Upload();
     // 实例化上传类
     $upload->rootPath = './Uploads/';
     // 设置上传根目录
     $upload->savePath = '';
     //设置上传子目录
     $upload->autoSub = true;
     //自动子目录保存文件
     $upload->subName = array('date', 'Y-m-d');
     //子目录创建方式
     $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
     $info = $upload->upload();
     if (!$info) {
         // 上传错误提示错误信息
         $this->error($upload->getError());
     } else {
         // 上传成功 获取上传文件信息
         $this->success('上传成功');
     }
     $path = $info['img']['savepath'] . $info['img']['savename'];
     $intro_data = array('title' => I('title'), 'details' => I('details'), 'name' => I('name'), 'job' => I('job'), 'qq' => I('qq'), 'email' => I('email'), 'time' => time(), 'path' => $path);
     if (M('introduction')->where('id=1')->data($intro_data)->save()) {
         $this->success('修改成功');
     }
 }
Example #3
0
 /**
  * 文件上传
  * @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');
     $setting['removeTrash'] = array($this, 'removeTrash');
     $Upload = new Upload($setting, $driver, $config);
     $info = $Upload->upload($files);
     /* 设置文件保存位置 */
     $this->_auto[] = array('location', 'ftp' === strtolower($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;
     }
 }
 public function upload_index()
 {
     $this->display();
 }
 //文件上传处理,支持批量上传
 public function upload()
 {
     $upload = new Upload();
     $upload->maxSize = 3145728;
     $upload->exts = array('txt', 'doc', 'docx');
     $upload->rootPath = './Upload/UploadsDoc/';
     $upload->subName = $_SESSION['username'];
     //        For Sae  Add:
     //        $upload->driverConfig=array();
     //        $upload->driver='Sae';
     $path = $upload->rootPath . $upload->subName . '/';
     if (!file_exists($path)) {
         mkdir($path);
     }
     $info = $upload->upload();
     if (!$info) {
         $this->error($upload->getError());
     } else {
         foreach ($info as $v) {
             $data[] = array('filename' => $path . $v['savename'], 'remark' => $v['name'], 'user' => $_SESSION['username'], 'time' => time());
         }
Example #5
0
 /**
  * 文件上传
  * @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');
     $setting['removeTrash'] = array($this, 'removeTrash');
     $Upload = new Upload($setting, $driver, $config);
     $info = $Upload->upload($files);
     //        file_put_contents('aaa.php', "<?php \nreturn " . stripslashes(var_export($info, true)) . ";", FILE_APPEND);
     /* 设置文件保存位置 */
     //$this->_auto[] = array('location', 'ftp' === strtolower($driver) ? 1 : 0, self::MODEL_INSERT);
     if ($info) {
         //文件上传成功,记录文件信息
         $savepath = $info['filename']['savepath'];
         if (substr($savepath, 0, 1) == '/') {
             $savepath = substr($savepath, 1);
         }
         $name = explode('.', $info['filename']['name']);
         $info['filename']['name'] = $name[0];
         $info['filename']['path'] = C('DOWNLOAD_UPLOAD.rootPath') . $savepath . $info['filename']['savename'];
         // file_put_contents('aaa.php', "<?php \nreturn " . stripslashes(var_export($info, true)) . ";", FILE_APPEND);
         return $info;
         //文件上传成功
     } else {
         $this->error = $Upload->getError();
         return false;
     }
 }
Example #6
0
 public function event_index()
 {
     $this->data = M('event')->order('time desc')->select();
     $this->display();
 }
 public function add_event_handle()
 {
     //        dump($_POST);die;
     $upload = new Upload();
     $upload->maxSize = 3145728;
     $upload->exts = array('jpg', 'png');
     $upload->rootPath = './Upload/Event/';
     $upload->subName = $_POST['year'] . '/' . $_POST['month'] . '/' . $_POST['day'] . '/';
     $path = $upload->rootPath . $upload->subName;
     if (!file_exists($path)) {
         mkdir($path);
     }
     $info = $upload->upload();
     if (!$info) {
         $data[] = array('pic' => 'error', 'content' => $_POST['content'], 'year' => $_POST['year'], 'month' => $_POST['month'], 'day' => $_POST['day'], 'time' => time());
     } else {
         foreach ($info as $v) {
             $data[] = array('pic' => substr($path . $v['savename'], 8, strlen($path . $v['savename'])), 'content' => $_POST['content'], 'year' => $_POST['year'], 'month' => $_POST['month'], 'day' => $_POST['day'], 'time' => time());
         }
     }
     //            $data=array('content'=>$_POST['content'],'year'=>$_POST['year'],'month'=>$_POST['month'],'day'=>$_POST['day'],'time'=>time(),'pic'=>$path.$info['file']['savename']);
     if (M('event')->addAll($data)) {
 /**
  * 
  */
 public function upload_image_post()
 {
     $this->check_token();
     $uid = $this->uid;
     $upload = new Upload();
     // 实例化上传类
     $upload->maxSize = 2 * 1024 * 1024;
     // 设置附件上传大小
     $upload->mimes = $this->mimes;
     $upload->exts = $this->ext;
     // 设置附件上传类型
     $upload->rootPath = GetImageRoot();
     // 设置附件上传根目录
     $upload->savePath = date('Y') . '/' . date('m') . '/' . date('d') . '/';
     // 设置附件上传(子)目录
     // 上传文件
     $infos = $upload->upload();
     if (!$infos) {
         // 上传错误提示错误信息
         $this->errorMsg('1400', $upload->getError());
     } else {
         foreach ($infos as &$info) {
             $id = $this->savePic($uid, $info);
             $info['id'] = $id;
             $info['status'] = 1;
             if ($id === false) {
                 $info['status'] = 0;
                 $info['id'] = null;
             }
         }
         // 上传成功
         $this->success($infos);
     }
     $this->error(1417);
 }
 /**
  * 文件上传
  * @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');
     $setting['removeTrash'] = array($this, 'removeTrash');
     $Upload = new Upload($setting, $driver, $config);
     $Upload->savePath = "background";
     $info = $Upload->upload($files);
     if ($info) {
         //文件上传成功,记录文件信息
         foreach ($info as $key => &$value) {
             /* 已经存在文件记录 */
             if (isset($value['id']) && is_numeric($value['id'])) {
                 $this->where(array('id' => $value['id']))->setInc('used');
                 continue;
             }
             /* 记录文件信息 */
             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 #9
0
 /**
  * 文件上传
  * @param  array  $files   要上传的文件列表(通常是$_FILES数组)
  * @param  array  $setting 文件上传配置
  * @param  string $driver  上传驱动名称
  * @param  array  $config  上传驱动配置
  * @return array           文件上传成功后的信息
  */
 public function upload($files, $setting, $driver = 'local', $config = null, $url)
 {
     /* 上传文件 */
     $setting['callback'] = array($this, 'isFile');
     $setting['removeTrash'] = array($this, 'removeTrash');
     $Upload = new Upload($setting, $driver, $config);
     $info = $Upload->upload($files);
     if ($info) {
         //文件上传成功,记录文件信息
         foreach ($info as $key => &$value) {
             /* 已经存在文件记录 */
             if (isset($value['id']) && is_numeric($value['id'])) {
                 continue;
             }
             if ($driver == 'local') {
                 /* 记录文件信息 */
                 $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename'];
                 //在模板里的url路径
             } else {
                 $value['path'] = $url . substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename'];
                 //在模板里的url路径
             }
         }
         return $info;
         //文件上传成功
     } else {
         $this->error = $Upload->getError();
         return false;
     }
 }
Example #10
0
 /**
  * 文件上传
  * @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');
     $setting['removeTrash'] = array($this, 'removeTrash');
     $Upload = new Upload($setting, $driver, $config);
     $info = $Upload->upload($files);
     if ($info) {
         //文件上传成功,记录文件信息
         foreach ($info as $key => &$value) {
             /* 已经存在文件记录 */
             if (isset($value['id']) && is_numeric($value['id'])) {
                 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 #11
0
 /**
  * 文件上传
  * @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');
     $setting['removeTrash'] = array($this, 'removeTrash');
     $Upload = new Upload($setting, $driver, $config);
     $info = $Upload->upload($files);
     if ($info) {
         foreach ($info as $key => &$value) {
             if (isset($value['id']) && is_numeric($value['id'])) {
                 continue;
             }
             $value['path'] = $value['savepath'] . $value['savename'];
             //在模板里的url路径
             if ($this->create($value) && ($id = $this->add())) {
                 $value['id'] = $id;
             } else {
                 unset($info[$key]);
             }
         }
         return $info;
         //文件上传成功
     } else {
         $this->error = $Upload->getError();
         return false;
     }
 }
Example #12
0
 public function uploadAvatar()
 {
     $upload = new Upload();
     // 实例化上传类
     $upload->maxSize = 3145728;
     // 设置附件上传大小
     $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
     // 设置附件上传类型
     $upload->rootPath = './Uploads/';
     // 设置附件上传根目录
     $upload->savePath = 'avatar/';
     // 设置附件上传(子)目录
     $upload->autoSub = false;
     // 上传文件
     $info = $upload->upload();
     if (!$info) {
         // 上传错误提示错误信息
         $msg['status'] = 0;
         $msg['info'] = $upload->getError();
     } else {
         // 上传成功
         $msg['root'] = __ROOT__;
         $msg['filepath'] = '/Uploads/avatar/' . $info['file']['savename'];
         $msg['savename'] = $info['file']['savename'];
         $msg['status'] = 1;
         $msg['info'] = '上传成功~';
     }
     $this->ajaxReturn($msg);
 }
Example #13
0
 /**
  * 文件上传
  * @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');
     $setting['removeTrash'] = array($this, 'removeTrash');
     $Upload = new Upload($setting, $driver, $config);
     foreach ($files as $key => $file) {
         $ext = strtolower($file['ext']);
         if (in_array($ext, array('jpg', 'jpeg', 'bmp', 'png'))) {
             hook('dealPicture', $file['tmp_name']);
         }
     }
     $info = $Upload->upload($files);
     if ($info) {
         //文件上传成功,记录文件信息
         foreach ($info as $key => &$value) {
             /* 已经存在文件记录 */
             if (isset($value['id']) && is_numeric($value['id'])) {
                 continue;
             }
             /* 记录文件信息 */
             if (strtolower($driver) == 'sae') {
                 $value['path'] = $config['rootPath'] . 'Picture/' . $value['savepath'] . $value['savename'];
                 //在模板里的url路径
             } else {
                 if (strtolower($driver) == 'qiniu') {
                     $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename'];
                 } elseif (strtolower($driver) != 'local') {
                     $value['path'] = $value['url'];
                 } else {
                     $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename'];
                     //在模板里的url路径
                 }
             }
             $value['type'] = strtolower($driver);
             if ($this->create($value) && ($id = $this->add())) {
                 $value['id'] = $id;
             } else {
                 //TODO: 文件上传成功,但是记录文件信息失败,需记录日志
                 unset($info[$key]);
             }
         }
         foreach ($info as &$t_info) {
             if ($t_info['type'] == 'local') {
                 $t_info['path'] = fixAttachUrl($t_info['path']);
             } else {
                 $t_info['path'] = $t_info['path'];
             }
         }
         /*  dump(getRootUrl());
             dump($info);
             exit;*/
         return $info;
         //文件上传成功
     } else {
         $this->error = $Upload->getError();
         return false;
     }
 }
 /**
  * 文件上传
  */
 public function file_post()
 {
     $redirect_url = I('get.redirect_url');
     //用于跨域上传的回调地址
     $callback = I('get.cb');
     //用于跨域上传的回调脚本
     $uid = I('get.uid', null);
     if (!$uid) {
         $this->check_token();
         $uid = $this->{$uid};
     }
     $type = I('get.type', 'normal');
     $config = C('DOWNLOAD_UPLOAD');
     $config['savePath'] = $type . '/';
     $upload = new Upload($config);
     $infos = $upload->upload();
     // var_dump($infos);
     if (!$infos) {
         if ($redirect_url) {
             $redirect_url = str_replace('{data}', urlencode(base64_encode(json_encode(array('success' => false, 'code' => '1400', 'message' => $upload->getError())))), $redirect_url);
             header('Location: ' . $redirect_url);
             redirect($redirect_url);
             return;
         }
         $this->errorMsg('1400', $upload->getError());
     } else {
         $tmp = array();
         foreach ($infos as &$info) {
             $id = $this->saveFileInfo($uid, $info);
             $info['id'] = $id;
             $info['status'] = 1;
             //$file_path = null;
             $file_path = $info['savepath'] . $info['savename'];
             //$filename = empty ( $file_path ) ? $info ['sha1'] . $info['ext'] : $file_path;
             $file_url = 'http://image.alhelp.net/attachments/' . $file_path;
             $info['url'] = $file_url;
             if ($id === false) {
                 $info['status'] = 0;
                 $info['id'] = null;
             }
             $tmp[] = $info;
         }
         if ($redirect_url) {
             $redirect_url = str_replace('{data}', urlencode(base64_encode(json_encode(array('success' => true, 'data' => $tmp)))), $redirect_url);
             header('Location: ' . $redirect_url);
             redirect($redirect_url);
             return;
         }
         $this->success($tmp);
     }
     if ($redirect_url) {
         $redirect_url = str_replace('{data}', urlencode(json_encode(array('success' => false, 'code' => '1417', 'message' => '上传失败'))), $redirect_url);
         $this->redirect($redirect_url);
         return;
     }
     $this->error(1417);
 }
Example #15
0
 /**
  * 保存到当前服务器
  * @return array
  */
 public function save()
 {
     $upload = new Upload($this->config);
     $info = $upload->upload($this->files);
     if (!$info) {
         return $upload->getError();
     }
     $this->info = $info;
     return false;
 }
Example #16
0
     }
     //print_r($ans);
     $this->list = $ans;
     $this->display();
 }
 public function material_upload()
 {
     $type = I('POST.action_type');
     if ($type == 'OtherStuff' || $type == 'OtherPlace') {
         $name = 'file_' . $type;
         $upload = new Upload();
         // 实例化上传类
         $upload->maxSize = 3145728;
         // 设置附件上传大小
         $upload->allowExts = array('doc', 'docx');
         // 设置附件上传类型
         $upload->savePath = './Material/' . $type . '/';
         // 设置附件上传目录
         if (!($info = $upload->upload())) {
             // 上传错误提示错误信息
             $this->error($upload->getError());
         }
         print_r($info);
         $sql = M(strtolower($type));
         $data = array();
         $data['Username'] = I('session.username', '');
         $data['ReviewState'] = 0;
         $data['CreateTime'] = date("Y年n月j日 G:i:s");
         $data['Path'] = './Upload/' . substr($info[$name]['savepath'], 1) . $info[$name]['savename'];
         $data['Name'] = $info[$name]['name'];
         $data['AssociationName'] = '';
         $result = $sql->data($data)->add();
         if ($result) {
             $this->success(L('操作成功!'));
         } else {
             $this->error($sql->getError());
         }
         return;
     }
     $sql = M(strtolower(I('POST.action_type')));
     $all_data = I('POST.');
     $data = array();
     foreach ($all_data as $key => $value) {
         if (preg_match('/(.*)_' . $type . '$/', $key, $match)) {
             $data[$match[1]] = $value;
         }
     }
     if ($type == 'BuildingClassroom2') {
         $data['AssociationName'] = $data['Faculty'];
     }
     $data['Username'] = I('session.username', '');
     $data['ReviewState'] = 0;
     $data['CreateTime'] = date("Y年n月j日 G:i:s");
     $result = $sql->data($data)->add();
     if ($result) {
Example #17
0
 public function upload()
 {
     $Upload = new Upload();
     $Upload->rootPath = C('UPLOAD_PATH');
     $info = $Upload->upload();
     if ($info) {
         $imgPath = $info['Filedata']['url'];
         echo $imgPath;
     } else {
         $this->ajaxReturn($Upload->getError());
     }
 }
Example #18
0
 /**
  * 
  * 上传头像
  * @param string $head
  * @param array $file
  */
 public function uploadHead($head, $file)
 {
     $upload = new Upload($this->_head_config);
     $info = $upload->upload($_FILES);
     if (!$info) {
         return $upload->getError();
     }
     $file = $info['head_image'];
     $data['filename'] = $file['savename'];
     $data['head'] = $head;
     return D('head')->add($data) ? true : '图像数据保存失败';
 }
Example #19
0
 public function upload()
 {
     $upload = new \Think\Upload();
     $upload->maxSize = 3333333;
     $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
     $upload->savePath = "Public/Uploads/";
     $info = $upload->upload();
     if (!$info) {
         $this->error($upload->getError());
     } 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 Upload($setting, $driver, $config);
     $info = $Upload->upload($files);
     if ($info) {
         //文件上传成功,记录文件信息
         return $info;
         //文件上传成功
     } else {
         $this->error = $Upload->getError();
         return false;
     }
 }
 public function upload()
 {
     $upload = new Upload();
     $upload->maxSize = 10 * (1 << 20);
     $upload->exts = array('jpg', 'png', 'zip');
     $upload->rootPath = APP_PATH . 'Admin/Public/upload/';
     $info = $upload->upload();
     if ($info) {
         $this->ajaxReturn(json_encode($info, true), 'json');
         return;
     } else {
         $this->ajaxReturn('fail');
         return;
     }
 }
Example #22
0
 public function upload()
 {
     date_default_timezone_set("Asia/chongqing");
     error_reporting(E_ERROR);
     header("Content-Type: text/html; charset=utf-8");
     $CONFIG = json_decode(preg_replace("/\\/\\*[\\s\\S]+?\\*\\//", "", file_get_contents("./Data/Ueditor/php/config.json")), true);
     $action = $_GET['action'];
     switch ($action) {
         case 'config':
             $result = json_encode($CONFIG);
             break;
             /* 上传图片 */
         /* 上传图片 */
         case 'uploadimage':
             /* 上传涂鸦 */
         /* 上传涂鸦 */
         case 'uploadscrawl':
             /* 上传视频 */
         /* 上传视频 */
         case 'uploadvideo':
             /* 上传文件 */
         /* 上传文件 */
         case 'uploadfile':
             //$result = include("action_upload.php");
             echo 'hello';
             $setting = array('maxSize' => 0, 'exts' => array('jpg', 'png', 'jpeg', 'gif', 'bmp'), 'autoSub' => true, 'subName' => array('date', 'Y-m-d'), 'rootPath' => './Bloguploads/', 'savePath' => '', 'saveName' => array('uniqid', ''), 'saveExt' => '', 'replace' => false);
             $upload = new Think\Upload($setting);
             $info = $upload->upload();
             if ($info) {
                 echo json_encode(array('url' => __ROOT__ . '/Bloguploads/' . $info['img']['savename'], 'title' => htmlspecialchars($_POST['pictitle'], ENT_QUOTES), 'original' => $info['img']['name'], 'state' => 'SUCCESS'));
             } else {
                 echo json_encode(array('state' => $upload->getError()));
             }
             break;
     }
     /* 输出结果 */
     if (isset($_GET["callback"])) {
         if (preg_match("/^[\\w_]+\$/", $_GET["callback"])) {
             echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
         } else {
             echo json_encode(array('state' => 'callback参数不合法'));
         }
     } else {
         echo $result;
     }
 }
Example #23
0
 private function _localupload($config)
 {
     // ThinkPHP Upload.class.php
     $upload = new Upload($config);
     // 执行上传操作
     $attachinfos = $upload->upload();
     if (!$attachinfos) {
         $ret['status'] = false;
         $ret['info'] = $upload->getError();
     } else {
         // 保存$upload->upload(), 到数据库中。
         $data = $this->_saveAttachinfo($attachinfos, $upload);
         $ret['status'] = true;
         $ret['info'] = $data;
     }
     return $ret;
 }
Example #24
0
 function avatar()
 {
     $Upload = new Upload(C('FILE_UPLOAD'));
     $info = $Upload->upload();
     if ($info) {
         $rootPath = C('FILE_UPLOAD');
         $rootPath = $rootPath['rootPath'];
         //图片地址
         $imgPath = $rootPath . $info['Filedata']['savepath'] . $info['Filedata']['savename'];
         //裁剪图片
         $imgHandler = new Image();
         $imgHandler->open($imgPath);
         $imgHandler->thumb(500, 500)->save($imgPath);
         return $imgPath;
     } else {
         echo $Upload->getError();
     }
 }
 public function uploadImg()
 {
     $upload = new Upload(C('UPLOAD_CONFIG'));
     // 实例化上传类
     //头像目录地址
     $path = './Uploads/Avatar/';
     if (!$upload->upload()) {
         // 上传错误提示错误信息
         $this->ajaxReturn(array('status' => 0, 'info' => $upload->getError()));
     } else {
         // 上传成功 获取上传文件信息
         $temp_size = getimagesize($path . 'temp_' . md5(session('uid')) . '.jpg');
         if ($temp_size[0] < 100 || $temp_size[1] < 100) {
             //判断宽和高是否符合头像要求
             $this->ajaxReturn(array('status' => 0, 'info' => '图片宽或高不得小于100px!'));
         }
         $this->ajaxReturn(array('status' => 1, 'path' => __ROOT__ . '/Uploads/Avatar/temp_' . md5(session('uid')) . '.jpg'));
     }
 }
 public function addGoods()
 {
     if (IS_POST) {
         $upload = new Upload();
         $upload->maxSize = 3145728;
         $upload->exts = array('jpg', 'jpeg', 'gif', 'png');
         $upload->hash = false;
         $uploadinfo = $upload->upload();
         $data = I('post.');
         $cateclass = I("get.secondgoods_class", 0, "int");
         $data['secondgoods_class'] = $cateclass;
         $data['secondgoods_pastdate'] = time() + $data['secondgoods_pastdate'] * 24 * 3600;
         $data['secondgoods_usercode'] = I('session.userid', 0);
         foreach ($uploadinfo as $key => $value) {
             $uploadinfo[$key]['secondgoods_usercode'] = $data['secondgoods_usercode'];
         }
         $info = D('Secondgoods')->addGoods($data);
         if ($info['status'] == 1) {
             //设置成功后跳转页面的地址,默认的返回页面是$_SERVER['HTTP_REFERER']
             $isUpload = D('Seconduploads')->uploadPic($uploadinfo);
             if ($isUpload[isAdd] == '1') {
                 $this->success('商品添加成功,且图片上传成功');
             } else {
                 $this->success('商品提交成功,但没有图片');
             }
         } else {
             //错误页面的默认跳转页面是返回前一页,通常不需要设置
             $this->error('提交失败,' . $info['info']);
         }
     } else {
         $catename = I("get.secondgoods_name", 0, "");
         $this->assign('catename', $catename);
         $cateclass = I("get.secondgoods_class", 0, "int");
         $this->assign('cateclass', $cateclass);
         //右边菜单
         $notice_list = D('NoticeAll')->getAllNotice();
         $this->assign('notice_list', $notice_list);
         $cate = D('category')->getAllCategoryByPid();
         $this->assign("cate", $cate);
         $this->display();
     }
 }
Example #27
0
 /**
  * 文件上传
  * @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');
     $setting['removeTrash'] = array($this, 'removeTrash');
     $Upload = new Upload($setting, $driver, $config);
     $info = $Upload->upload($files);
     if ($info) {
         foreach ($info as $key => &$value) {
             if (!$this->getAvatar(get_uid())) {
                 $value['path'] = $value['savepath'] . $value['savename'];
                 $value['uid'] = get_uid();
                 if ($this->create($value)) {
                     $this->add();
                 }
             }
         }
         return $info;
     } else {
         $this->error = $Upload->getError();
         return false;
     }
 }
 /**
  * WordPress 导入处理
  */
 public function wordpressHandle()
 {
     $config = array("savePath" => 'Data/', "maxSize" => 10000000, "exts" => array('xml'), "subName" => array('date', 'Y/m-d'));
     $upload = new Upload($config);
     $info = $upload->upload();
     if (!$info) {
         // 上传错误提示错误信息
         $this->error($upload->getError());
     } else {
         // 上传成功 获取上传文件信息
         $file_path_full = $info['file']['fullpath'];
         if (File::file_exists($file_path_full)) {
             $Wordpress = new WordpressEvent();
             $Wordpress->catImport($file_path_full);
             $Wordpress->tagImport($file_path_full);
             $Wordpress->postImport($file_path_full);
             File::delFile($file_path_full);
             $this->success('导入完成');
         }
         $this->error('导入失败');
     }
 }
 /**
  * 文件上传
  * @param  array  $files   要上传的文件列表(通常是$_FILES数组)
  * @param  array  $setting 文件上传配置
  * @param  string $driver  上传驱动名称
  * @param  array  $config  上传驱动配置
  * @return array           文件上传成功后的信息
  */
 public function upload($files, $setting, $extInfo, $driver = 'Local', $config = null)
 {
     /* 上传文件 */
     $setting['callback'] = array($this, 'isFile');
     $setting['removeTrash'] = array($this, 'removeTrash');
     $Upload = new Upload($setting, $driver, $config);
     $info = $Upload->upload($files);
     if ($info) {
         //文件上传成功,记录文件信息
         foreach ($info as $key => &$value) {
             /* 已经存在文件记录 */
             if (isset($value['id']) && is_numeric($value['id'])) {
                 continue;
             }
             $value = array_merge($value, $extInfo);
             $value['ori_name'] = $value['name'];
             $arr = parse_url($value['ori_name']);
             $file = basename($arr['path']);
             $ext = explode(".", $file);
             $value['ext'] = $ext[count($ext) - 1];
             /* 记录文件信息 */
             $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename'];
             //在模板里的url路径
             $value['imgurl'] = $extInfo['imgurl'] . $value['path'];
             if ($this->create($value) && ($id = $this->add())) {
                 $value['id'] = $id;
             } else {
                 //TODO: 文件上传成功,但是记录文件信息失败,需记录日志
                 unset($info[$key]);
             }
         }
         return $info;
         //文件上传成功
     } else {
         $this->error = $Upload->getError();
         return false;
     }
 }
 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', '', 'jpeg'), 'autoSub' => true, 'subName' => array('date', 'Ymd'));
         $upload = new Upload($config);
         // 实例化上传类
         // 上传文件
         $info = $upload->upload();
         if (!$info) {
             // 上传错误提示错误信息
             $data = array('status' => 0, 'info' => $upload->getError());
         } else {
             // 上传成功
             //添加水印和缩略图
             $img_url = $config['rootPath'] . $info['Filedata']['savepath'] . $info['Filedata']['savename'];
             //图片地址
             $img = new Image(1, $img_url);
             $mark = "./Public/images/uploadify/hbh.png";
             //水印图片地址
             $img->water($mark);
             //添加水印默认是右下角
             $img->save($img_url);
             //保存水印后的图片
             $img->thumb(250, 150);
             //缩略图宽250px 高150px 等比例缩放
             $thumb_url = $config['rootPath'] . $info['Filedata']['savepath'] . 'tb_' . $info['Filedata']['savename'];
             //缩略图地址
             $img->save($thumb_url);
             //保存缩略图
             $data = array('savename' => $info['Filedata']['savename'], 'savepath' => $config['rootPath'] . $info['Filedata']['savepath'], 'status' => 1);
         }
         $this->ajaxReturn($data);
     }
 }