zjh il y a 3 mois
Parent
commit
e47959825c
4 fichiers modifiés avec 26 ajouts et 5 suppressions
  1. 13 0
      src/Config/Mine.php
  2. 1 1
      src/Driver/Base.php
  3. 2 1
      src/Driver/Entity/Base.php
  4. 10 3
      src/Library/Upload.php

+ 13 - 0
src/Config/Mine.php

@@ -219,6 +219,19 @@ class Mine
     {
     }
 
+    /**
+     * 是否是有效的文件类型
+     *
+     * @param string $type application/vnd.android.package-archive
+     * @return bool
+     */
+    public function isAvaliable($type) {
+        return in_array($type, array_values($this->mine));
+    }
+
+    public function extension($type) {
+        return array_search($type, $this->mine);
+    }
     /**
      * 通过 $this->get{对应的文件类型} 来获取mineType,或者getAll获取所有的
      *

+ 1 - 1
src/Driver/Base.php

@@ -751,7 +751,7 @@ class Base
 
     /**
      * GROUP BY
-     * @param mix $group
+     * @param mixed $group
      * @return $this
      */
     public function groupBy($group)

+ 2 - 1
src/Driver/Entity/Base.php

@@ -642,7 +642,8 @@ class Base {
         $this->uniqKeys = $uniqKeys;
     }
     /**
-     * unique (unique 如果是 array 则表示 联合唯一,如果是string则是任意唯一,多个单独唯一使用字符串以逗号隔开, 主键除外)
+     * unique (unique 如果是 array('a,b') 则表示 a,b联合唯一,array('a,b', 'b,c') 表示a,b唯一 或 b,c唯一
+     * 'a,b' 字符串则表示任意唯一 类似于array ('a','b')
      *
      * @return mixed
      * @throws \Exception

+ 10 - 3
src/Library/Upload.php

@@ -187,6 +187,10 @@ class Upload
                     'error' => $files['error'][$key],
                     'size' => $files['size'][$key]
                 );
+                // 多文件上传指定文件名的时候使用
+                if(isset($configure['fileNames'][$key])) {
+                    $configure['fileName'] = $configure['fileNames'][$key];
+                }
                 $data['files'][] = $this->deal($file, $configure, $key);
             }
             return $data;
@@ -231,12 +235,14 @@ class Upload
         
         $extension = '.' . $extension;
         //如果是设置了保持文件名称的话,就不自动转换文件名
-        if (isset($configure['keepFileName']) && $configure['keepFileName']) {
+        if(isset($configure['fileName'])) {
+            $fileName = $configure['fileName'];
+        }else if (isset($configure['keepFileName']) && $configure['keepFileName']) {
             $fileName = pathinfo($files['name'], PATHINFO_FILENAME);
         } else {
             $fileName = rand(10000, 90000) . uniqid();
         }
-        $configure['fileName'] = $configure['prefix'] . $fileName . $extension;
+        $fullName = $configure['prefix'] . $fileName . $extension;
         $subDir = $this->distribution($fileName, $configure['maxFolder']);
         
         $fillPath = $configure['path'];
@@ -253,7 +259,7 @@ class Upload
             }
         }
         //将文件名转换成URL编码,防止移动文件不成功的情况
-        $realPath = rtrim($fillPath, '/') . '/' . $configure['fileName'];
+        $realPath = rtrim($fillPath, '/') . '/' . $fullName;
         if ($files['binary']) {
             $result = @rename($files['tmp_name'], $realPath);
         } else {
@@ -264,6 +270,7 @@ class Upload
             $data['src'] = toUTF8($realPath);
             $data['name'] = toUTF8($files['name']);
             $data['file_type'] = $files['type'];
+            $data['extension'] = $extension;
             $data['file_hash'] = $this->fileHash($realPath);
             $data['size'] = $files['size'];
         } else {