當前位置: 首頁>>代碼示例>>PHP>>正文


PHP think\Upload類代碼示例

本文整理匯總了PHP中think\Upload的典型用法代碼示例。如果您正苦於以下問題:PHP Upload類的具體用法?PHP Upload怎麽用?PHP Upload使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Upload類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: uploadImg

 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('產品信息更新失敗');
         }
     }
 }
開發者ID:yuhaizr,項目名稱:Y2Game,代碼行數:28,代碼來源:UploadController.class.php

示例2: introHandle

 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('修改成功');
     }
 }
開發者ID:Gumtrip,項目名稱:blog,代碼行數:27,代碼來源:IntroController.class.php

示例3: myUpdate

 public function myUpdate($data)
 {
     $id = (int) $data['id'];
     unset($data['id']);
     if (empty($data['password'])) {
         unset($data['password']);
     } else {
         $data['password'] = pwd_hash($data['password']);
     }
     if (false === $this->create($data, self::MODEL_UPDATE)) {
         return false;
     }
     //上傳店鋪logo
     if (!empty($data['store_logo'])) {
         $setting = C('PICTURE_UPLOAD');
         $Upload = new Upload($setting);
         $store_logo = $Upload->uploadOne($data['store_logo']);
         if (!$store_logo) {
             $this->error = $Upload->getError();
             return false;
         }
         $store_logo['path'] = substr($setting['rootPath'], 1) . $store_logo['savepath'] . $store_logo['savename'];
         //在模板裏的url路徑
         $this->store_logo = $store_logo['path'];
     } else {
         unset($this->store_logo);
     }
     return $this->where('`id`=' . $id)->save();
 }
開發者ID:hcpzhe,項目名稱:foodorder,代碼行數:29,代碼來源:StoreModel.class.php

示例4: event_index

 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)) {
開發者ID:TedaLIEz,項目名稱:AUNET,代碼行數:27,代碼來源:EventController.class.php

示例5: upload

 public function upload()
 {
     header("Content-Type:text/html;charset=utf-8");
     $upload = new Upload();
     // 實例化上傳類
     $upload->maxSize = 3145728;
     // 設置附件上傳大小(默認3M)
     $upload->exts = array('xls', 'xlsx');
     // 設置附件上傳類
     $upload->savePath = '/';
     // 設置附件上傳目錄
     // 上傳文件
     $parent = $upload->uploadOne($_FILES['parent-file']);
     // 父訂單文件
     $child = $upload->uploadOne($_FILES['child-file']);
     // 子訂單文件
     //        var_dump($info);
     $parentFile = './Uploads' . $parent['savepath'] . $parent['savename'];
     $chileFile = './Uploads' . $child['savepath'] . $child['savename'];
     // 獲取文件後綴名
     $parentExts = $parent['ext'];
     $childExts = $parent['ext'];
     if ($parent && $child) {
         // 上傳成功後導入數據
         $this->import_data($parentFile, $chileFile, $parentExts, $childExts);
         //            sleep(10);
         //            刪除文件
         //            unlink($filename);
     } else {
         //            上傳錯誤提示錯誤信息
         //            $this->error($upload->getError());
         $this->error("上傳文件不完整或沒有文件被上傳!");
     }
 }
開發者ID:Aaron-zh,項目名稱:ThinkPHPFull,代碼行數:34,代碼來源:UploadController.class.php

示例6: upload

 /**
  * 文件上傳
  * @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;
     }
 }
開發者ID:GuiFox,項目名稱:Morplee,代碼行數:38,代碼來源:FileModel.class.php

示例7: upload

 /**
  * 文件上傳
  * @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;
     }
 }
開發者ID:walkingmanc,項目名稱:weshop,代碼行數:43,代碼來源:FileModel.class.php

示例8: upload

 /**
  * 文件上傳
  * @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;
     }
 }
開發者ID:jkzleond,項目名稱:alhelp_api,代碼行數:35,代碼來源:FileModel.class.php

示例9: upload

 /**
  * 文件上傳
  * @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;
     }
 }
開發者ID:HarrryStudio,項目名稱:microweb,代碼行數:39,代碼來源:PictureModel.class.php

示例10: uploadAvatar

 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);
 }
開發者ID:guiguoershao,項目名稱:okr,代碼行數:29,代碼來源:UserController.class.php

示例11: upload_image_post

 /**
  * 
  */
 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);
 }
開發者ID:jkzleond,項目名稱:alhelp_api,代碼行數:38,代碼來源:ImagesController.class.php

示例12: upload

 /**
  * 文件上傳
  * @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;
     }
 }
開發者ID:Germey,項目名稱:SimpleCMS,代碼行數:39,代碼來源:PictureModel.class.php

示例13: upload

 /**
  * 文件上傳
  * @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;
     }
 }
開發者ID:nullog,項目名稱:zhanglubao,代碼行數:35,代碼來源:PictureModel.class.php

示例14: upload_index

 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());
         }
開發者ID:TedaLIEz,項目名稱:AUNET,代碼行數:26,代碼來源:UploadController.class.php

示例15: index

 public function index()
 {
     $dir = I('post.dir');
     //獲取
     $config = array('rootPath' => './Uploads/', 'savePath' => $dir . '/', 'driver' => '', 'driverConfig' => array());
     //      $config = array(
     //
     //          'rootPath'     => './', //保存到upyun的根路徑
     //          'driver'       => 'Upyun', // 文件上傳驅動
     //          'driverConfig' => array(
     //              'host'     => 'v0.api.upyun.com', //又拍雲服務器
     //              'username' => 'itsource', //又拍操作員用戶
     //              'password' => 'itsource', //又拍雲操作員密碼
     //              'bucket'   => $dir, //空間名稱
     //              'timeout'  => 90, //超時時間
     //          ), // 上傳驅動配置
     //      );
     //實例化對象
     $uploader = new Upload($config);
     //上傳上來的名字
     $result = $uploader->uploadOne($_FILES['Filedata']);
     if ($result !== false) {
         //將上傳後的路徑發送給瀏覽器
         echo $result['savepath'] . $result['savename'];
         //保存路徑和名字  不包含根路徑
     } else {
         echo $uploader->getError();
     }
 }
開發者ID:EasySilent,項目名稱:php1009,代碼行數:29,代碼來源:UploadController.class.php


注:本文中的think\Upload類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。