rabin 2 mesiacov pred
rodič
commit
c7d4f584c3
5 zmenil súbory, kde vykonal 44 pridanie a 5 odobranie
  1. 1 1
      api/Save.php
  2. 10 4
      lib/Save.php
  3. 24 0
      table/cate.php
  4. 8 0
      table/file.php
  5. 1 0
      table/manage/file.php

+ 1 - 1
api/Save.php

@@ -17,7 +17,7 @@ class Save
         }
         Dever::config('setting', array('output' => array
         (
-            'status' => array('errno', array('1' => '0', '2' => '1')),
+            'status' => array('errno', array('1' => 0, '2' => 1)),
             'msg' => 'message',
         )));
         return $this->act($id, $file);

+ 10 - 4
lib/Save.php

@@ -58,7 +58,7 @@ class Save
         return $result;
     }
 
-    public function act($id, $source, $default_ext = '', $uid = false)
+    public function act($id, $source, $default_ext = '', $uid = false, $dest_name = '', $cate = 1)
     {
         $this->init($id);
         $name = '';
@@ -150,10 +150,13 @@ class Save
             }
             Dever::error($state);
         }
+        if ($dest_name) {
+            $name = $dest_name;
+        }
         $dest = $this->config['id'] . '/' . $this->getDest($name, $ext, $uid);
         # type 1是文件复制 2是base64 3是远程文件复制
         $url = Dever::load('tool', 'upload')->get($this->config['save'])->upload($type, $source, $dest, $chunk, $this);
-        $data = $this->up($source_name, $name, $dest, $this->config['size'], $this->config['width'] ?? 0, $this->config['height'] ?? 0);
+        $data = $this->up($source_name, $name, $dest, $this->config['size'], $this->config['width'] ?? 0, $this->config['height'] ?? 0, $cate);
         $data['url'] = $url;
         $data['type'] = $this->type;
         if (isset($content)) {
@@ -176,7 +179,7 @@ class Save
         return $data;
     }
 
-    private function up($source_name, $name, $dest, $size, $width = 0, $height = 0)
+    private function up($source_name, $name, $dest, $size, $width = 0, $height = 0, $cate = 1)
     {
         $file['rule_id'] = $this->config['id'];
         $file['name'] = $name;
@@ -191,6 +194,7 @@ class Save
         if ($height) {
             $data['height'] = $height;
         }
+        $data['cate_id'] = $cate;
         $data['id'] = Dever::db('file', 'upload')->up($file, $data);
         return $data;
     }
@@ -303,7 +307,9 @@ class Save
             $dest = DIRECTORY_SEPARATOR . substr($id, 0, 3) . DIRECTORY_SEPARATOR . substr($id, 3, 2) . DIRECTORY_SEPARATOR . substr($id, 5, 2) . DIRECTORY_SEPARATOR . $uid . '.' . $ext;
             $name = $uid;
         } else {
-            $name = md5($name);
+            if (!strpos($name, '_')) {
+                $name = md5($name);
+            }
             $path = array_slice(str_split($name, 2), 0, 3);
             $dest = implode(DIRECTORY_SEPARATOR, $path) . DIRECTORY_SEPARATOR . $name . '.' . $ext;
         }

+ 24 - 0
table/cate.php

@@ -0,0 +1,24 @@
+<?php
+return array
+(
+    'name' => '文件分类',
+    # 数据结构
+    'struct' => array
+    (
+        'name'      => array
+        (
+            'name'      => '名称',
+            'type'      => 'varchar(24)',
+        ),
+    ),
+    'default' => array
+    (
+        'field' => 'name,cdate',
+        'value' => array
+        (
+            '"默认",' . DEVER_TIME,
+            '"裁剪",' . DEVER_TIME,
+        ),
+        'num' => 1,
+    ),
+);

+ 8 - 0
table/file.php

@@ -23,6 +23,14 @@ return array
             'type'      => 'varchar(200)',
         ),
 
+        'cate_id'     => array
+        (
+            'name'      => '文件分类',
+            'type'      => 'int(11)',
+            'value'     => 'upload/cate',
+            'default'   => '1',
+        ),
+
         'save_id'     => array
         (
             'name'      => '存储位置',

+ 1 - 0
table/manage/file.php

@@ -8,6 +8,7 @@ return array
         'search' => array
         (
             'name',
+            'cate_id',
             'file',
             'status',
         ),