dever vor 4 Jahren
Ursprung
Commit
50fe046569
3 geänderte Dateien mit 20 neuen und 7 gelöschten Zeilen
  1. 3 2
      database/file.php
  2. 2 2
      database/upload.php
  3. 15 3
      lib/Store/Core.php

+ 3 - 2
database/file.php

@@ -245,12 +245,13 @@ return array
 	'index' => array
 	(
 		# 索引名 => 索引id
-		2 => array
+		3 => array
 		(
 			'search' => '`key`,cate,search',
+			'name' => 'name',
 		),
 
-		'version' => 2,
+		'version' => 3,
 	),
 
 	# 更新表结构

+ 2 - 2
database/upload.php

@@ -131,8 +131,8 @@ return array
 		'cover'		=> array
 		(
 			'type' 		=> 'int-1',
-			'name' 		=> '是否覆盖',
-			'default' 	=> '3',
+			'name' 		=> '是否覆盖-将根据上传时的文件名进行文件覆盖操作',
+			'default' 	=> '1',
 			'desc' 		=> '请选择是否覆盖',
 			'match' 	=> 'is_numeric',
 			'option' 	=> $cover,

+ 15 - 3
lib/Store/Core.php

@@ -413,14 +413,26 @@ class Core
 
 	protected function getName()
     {
-        $this->path()->name($this->data['file']['name'])->ext()->file();
+        $this->name($this->data['file']['name'])->path()->ext()->file();
     }
 
 	protected function path()
 	{
-		$date = explode('-', date("Y-m-d"));
+		# 覆盖原文件 检查文件是否存在
+		$this->path = '';
+		if ($this->config['cover'] == 1) {
+			$info = Dever::db('upload/file')->one(array('name' => $this->name));
+			if ($info && $info['file'] && strstr($info['file'], $this->name)) {
+				# 如果存在,直接使用旧文件
+				$temp = explode($this->name, $info['file']);
+				$this->path = $temp[0];
+			}
+		}
 
-		$this->path = $this->config['id'] . '/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/';
+		if (!$this->path) {
+			$date = explode('-', date("Y-m-d"));
+			$this->path = $this->config['id'] . '/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/';
+		}
 
 		return $this;
 	}