瀏覽代碼

可在配置文件配置上传到七牛

star7th 9 年之前
父節點
當前提交
4e8b9b3295
共有 2 個文件被更改,包括 49 次插入12 次删除
  1. 21 12
      Application/Home/Controller/PageController.class.php
  2. 28 0
      install/ajax.php

+ 21 - 12
Application/Home/Controller/PageController.class.php

@@ -277,20 +277,29 @@ class PageController extends BaseController {
 
     //上传图片
     public function uploadImg(){
-        $upload = new \Think\Upload();// 实例化上传类
-        $upload->maxSize  = 3145728 ;// 设置附件上传大小
-        $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
-        $upload->rootPath = './Public/Uploads/';// 设置附件上传目录
-        $upload->savePath = '';// 设置附件上传子目录
-        $info = $upload->upload() ;
-        if(!$info) {// 上传错误提示错误信息
-          $this->error($upload->getError());
-          return;
-        }else{// 上传成功 获取上传文件信息
-          
-          $url = get_domain().__ROOT__.substr($upload->rootPath,1).$info['editormd-image-file']['savepath'].$info['editormd-image-file']['savename'] ;
+        $qiniu_config = C('UPLOAD_SITEIMG_QINIU') ;
+        if (!empty($qiniu_config['driverConfig']['secrectKey'])) {
+          //上传到七牛
+          $Upload = new \Think\Upload(C('UPLOAD_SITEIMG_QINIU'));
+          $info = $Upload->upload($_FILES);
+          $url = $info['editormd-image-file']['url'] ;
           echo json_encode(array("url"=>$url,"success"=>1));
+        }else{
+            $upload = new \Think\Upload();// 实例化上传类
+            $upload->maxSize  = 3145728 ;// 设置附件上传大小
+            $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
+            $upload->rootPath = './Public/Uploads/';// 设置附件上传目录
+            $upload->savePath = '';// 设置附件上传子目录
+            $info = $upload->upload() ;
+            if(!$info) {// 上传错误提示错误信息
+              $this->error($upload->getError());
+              return;
+            }else{// 上传成功 获取上传文件信息
+              $url = get_domain().__ROOT__.substr($upload->rootPath,1).$info['editormd-image-file']['savepath'].$info['editormd-image-file']['savename'] ;
+              echo json_encode(array("url"=>$url,"success"=>1));
+            }
         }
+
     }
 
 

+ 28 - 0
install/ajax.php

@@ -76,6 +76,20 @@ return array(
     ),
     'URL_CASE_INSENSITIVE'=>true,
     'SHOW_ERROR_MSG'        =>  true,    // 显示错误信息,这样在部署模式下也能显示错误
+    'STATS_CODE' =>'',  //可选,统计代码
+    //上传文件到七牛的配置
+    'UPLOAD_SITEIMG_QINIU' => array(
+                    'maxSize' => 5 * 1024 * 1024,//文件大小
+                    'rootPath' => './',
+                    'saveName' => array ('uniqid', ''),
+                    'driver' => 'Qiniu',
+                    'driverConfig' => array (
+                            'secrectKey' => '', 
+                            'accessKey' => '',
+                            'domain' => '',
+                            'bucket' => '', 
+                        )
+                    ),
 );
 EOD;
         $ret = file_put_contents("../Application/Common/Conf/config.php", $config);
@@ -147,6 +161,20 @@ return array(
     ),
     'URL_CASE_INSENSITIVE'=>true,
     'SHOW_ERROR_MSG'        =>  true,    // 显示错误信息,这样在部署模式下也能显示错误
+    'STATS_CODE' =>'',  //可选,统计代码
+    //上传文件到七牛的配置
+    'UPLOAD_SITEIMG_QINIU' => array(
+                    'maxSize' => 5 * 1024 * 1024,//文件大小
+                    'rootPath' => './',
+                    'saveName' => array ('uniqid', ''),
+                    'driver' => 'Qiniu',
+                    'driverConfig' => array (
+                            'secrectKey' => '', 
+                            'accessKey' => '',
+                            'domain' => '',
+                            'bucket' => '', 
+                        )
+                    ),
 );";
         $ret = file_put_contents("../Application/Common/Conf/config.php", $config);