wupengfei 2 years ago
parent
commit
7a154c2f6f

+ 3 - 0
.idea/workspace.xml

@@ -2,7 +2,10 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="1a36929e-c054-4875-a943-593a74e55fa4" name="Default Changelist" comment="">
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/application/api/controller/Upload.php" beforeDir="false" afterPath="$PROJECT_DIR$/application/api/controller/Upload.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/application/common.php" beforeDir="false" afterPath="$PROJECT_DIR$/application/common.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/application/nutrition/view/one_datum/form.html" beforeDir="false" afterPath="$PROJECT_DIR$/application/nutrition/view/one_datum/form.html" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />

+ 6 - 24
application/api/controller/Upload.php

@@ -84,37 +84,19 @@ class Upload extends Base
      */
     public function pdfUpload()
     {
-        if (!($file = $this->getUploadFile()) || empty($file)) {
-            $this->error('文件上传异常,文件可能过大或未上传!');
-        }
-        if (!$file->checkExt(strtolower(sysconf('storage_local_exts')))) {
-            $this->error('文件上传类型受限,请在后台配置!');
-        }
-        if ($file->checkExt('php,sh')) {
-            $this->error('可执行文件禁止上传到本地服务器!');
-        }
+        if (!($file = $this->getUploadFile()) || empty($file)) $this->error('文件上传异常,文件可能过大或未上传!');
+        if (!$file->checkExt(strtolower(sysconf('storage_local_exts')))) $this->error('文件上传类型受限,请在后台配置!');
+        if ($file->checkExt('php,sh')) $this->error('可执行文件禁止上传到本地服务器!');
         $file_info = $file->getInfo();
-
         $ext = pathinfo($file_info['name'],PATHINFO_EXTENSION);
         $file_name = pathinfo($file_info['name'],PATHINFO_FILENAME);
         $new_name  = $file_name.date("Y-m-d H:i:s").'.'.$ext;
-        var_dump($_SERVER);
         $save_path = $_SERVER['DOCUMENT_ROOT'].'/static/pdf'.$new_name;
-        $res = move_uploaded_file($file_info['tmp_name'],$save_path);
-        var_dump($res,$save_path);
+        move_uploaded_file($file_info['tmp_name'],$save_path);
         $res = pdfCurl($save_path);
-        var_dump($res);
         unlink($save_path);
-        die();
-        $headers = [];
-        $headers[] = 'Content-Type: application/x-www-form-urlencoded';
-       // $res = pdfCurl($_SERVER['DOCUMENT_ROOT'].'/dist/img/bg-1.79910aaf.png');
-        var_dump($file->getInfo()['']);
-        $res = pdfCurl('/tmp/phpQayTEp');
-        //var_dump(curlPost('http://101.132.128.55:9999/v1/pdf/upload',$_FILES['file']),$_FILES);
-        var_dump($res);
-
-
+        if(!empty($res) && $res['code'] == 1) $this->success('上传成功','http://gaoyixia.oss-cn-hangzhou.aliyuncs.com'.$res['data']);
+        $this->error('上传失败');
     }
 
 

+ 1 - 1
application/common.php

@@ -359,7 +359,7 @@ function pdfCurl($file_name)
         echo 'Error:' . curl_error($ch);
     }
     curl_close($ch);
-    return $result;
+    return  json_decode($result,true);
 }
 
 function curlPost($url, $post_data = array(), $timeout = 5, $header = "", $data_type = "") {

+ 1 - 6
application/nutrition/view/one_datum/form.html

@@ -68,13 +68,8 @@
                 ,layer = layui.layer;
             upload.render({
                 elem: '#test3',
-                url: 'http://101.132.128.55:9999/v1/pdf/upload', //此处用的是第三方的 http 请求演示,实际使用时改成您自己的上传接口即可。,accept: 'file', //普通文件,
+                url: '/api/upload/pdfUpload', //此处用的是第三方的 http 请求演示,实际使用时改成您自己的上传接口即可。,accept: 'file', //普通文件,
                 accept: 'multipart/form-data', //普通文件,
-                headers: {
-                    //"Content-Type": "multipart/form-data",
-                    "Content-Type": "application/x-www-form-urlencoded"
-                },
-
                 done: function(res){
                     console.log(res)
                     $("input[name='datum_url']").val(res.data);