rabin 6 years ago
commit
366e5b4363
14 changed files with 1303 additions and 0 deletions
  1. 14 0
      LICENSE
  2. 2 0
      README.md
  3. 26 0
      api/main.php
  4. 6 0
      crossdomain.xml
  5. 160 0
      database/file.php
  6. 103 0
      database/pic_crop.php
  7. 121 0
      database/pic_thumb.php
  8. 115 0
      database/pic_water.php
  9. 158 0
      database/upload.php
  10. 7 0
      index.php
  11. 75 0
      src/Save.php
  12. 13 0
      src/Store/Config.php
  13. 348 0
      src/Store/Core.php
  14. 155 0
      src/Store/Local.php

+ 14 - 0
LICENSE

@@ -0,0 +1,14 @@
+Apache License
+Copyright 2016-2017 Dever(dever.cc)
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.

+ 2 - 0
README.md

@@ -0,0 +1,2 @@
+# upload
+

+ 26 - 0
api/main.php

@@ -0,0 +1,26 @@
+<?php
+# 注册api
+# api仅有三种类型:get、update、delete,每种类型对应的加密key不同 1,2,3
+
+return array
+(
+	'save.action' => array
+	(
+		# 接口名
+		'name' => '上传文件',
+		# 请求参数
+		'request' => array
+		(
+			'file' => '流文件',
+			'key' => '上传的配置id',
+		),
+		# 返回参数 一般定义给外部使用的,此处无实际意义
+		'response' => array
+		(
+			'file' => '文件地址',
+		),
+		'order' => 100,
+		# 接口类型
+		'type' => 1,
+	),
+);

+ 6 - 0
crossdomain.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd" >
+<cross-domain-policy>
+	<allow-access-from domain="*" />
+	<allow-http-request-headers-from domain="*" headers="*"/>
+</cross-domain-policy>

+ 160 - 0
database/file.php

@@ -0,0 +1,160 @@
+<?php
+/**
+ * 上传表
+ * demo: data/upload/upload_name/10000/10/10.thumb_test.jpg
+ * 基本操作:根据upload上传、保存到pic表,所有保存到pic表的图片,均可参与后续处理操作 
+ */
+ 
+# 定义几个常用的选项
+$option = array
+(
+	1 => '启用',
+	2 => '关闭',
+);
+
+return array
+(
+	# 表名
+	'name' => 'file',
+	# 显示给用户看的名称
+	'lang' => '文件管理',
+	'order' => 9,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			//'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-32',
+			'name' 		=> '文件名',
+			'default' 	=> '',
+			'desc' 		=> '请输入文件名',
+			'match' 	=> 'is_string',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'source_name'		=> array
+		(
+			'type' 		=> 'varchar-50',
+			'name' 		=> '原文件名',
+			'default' 	=> '',
+			'desc' 		=> '请输入原文件名',
+			'match' 	=> 'is_string',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-32',
+			'name' 		=> 'key',
+			'default' 	=> '',
+			'desc' 		=> 'key',
+			'match' 	=> 'is_string',
+			//'search'	=> 'fulltext',
+			//'list'		=> true,
+		),
+		
+		'ext'		=> array
+		(
+			'type' 		=> 'varchar-24',
+			'name' 		=> '后缀名',
+			'default' 	=> '',
+			'desc' 		=> '请输入后缀名',
+			'match' 	=> 'is_string',
+			'list'		=> true,
+		),
+		
+		'file'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '访问路径',
+			'default' 	=> '',
+			'desc' 		=> '请输入访问路径',
+			'match' 	=> 'is_string',
+			'list'		=> true,
+		),
+		
+		'width'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '宽度',
+			'default' 	=> '0',
+			'desc' 		=> '请输入宽度',
+			'match' 	=> 'option',
+			'list'		=> true,
+		),
+		
+		'height'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '高度',
+			'default' 	=> '0',
+			'desc' 		=> '请输入高度',
+			'match' 	=> 'option',
+			'list'		=> true,
+		),
+		
+		'size'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '大小',
+			'default' 	=> '0',
+			'desc' 		=> '请输入大小',
+			'match' 	=> 'option',
+			'list'		=> true,
+		),
+		
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	
+	# request 请求接口定义
+	'request' => array
+	(
+		# info 根据文件名获取数据
+		'file' => array
+		(
+			'where' => array
+			(
+				'file' => 'is_string',
+			),
+			'type' => 'one',
+		),
+		
+		'name' => array
+		(
+			'where' => array
+			(
+				'name' => 'is_string',
+			),
+			'type' => 'one',
+		),
+	)
+);

+ 103 - 0
database/pic_crop.php

@@ -0,0 +1,103 @@
+<?php
+/**
+ * 上传表
+ */
+ 
+# 定义几个常用的选项
+$option = array
+(
+	1 => '启用',
+	2 => '关闭',
+);
+
+return array
+(
+	# 表名
+	'name' => 'pic_crop',
+	# 显示给用户看的名称
+	'lang' => '裁剪图配置',
+	//'menu' => false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '配置ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-24',
+			'name' 		=> '配置名',
+			'default' 	=> '',
+			'desc' 		=> '请输入配置名',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+		
+		'width'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '宽度',
+			'default' 	=> '0',
+			'desc' 		=> '请输入宽度',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+		
+		'height'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '高度',
+			'default' 	=> '0',
+			'desc' 		=> '请输入高度',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+		
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	# request 请求接口定义
+	'request' => array
+	(
+		# info 取一条正常的数据
+		'info' => array
+		(
+			# 匹配的正则或函数 必填项
+			'where' => array
+			(
+				'id' => 'is_numeric',
+				'state' => 1,
+			),
+			'type' => 'one',
+		),
+	),
+);

+ 121 - 0
database/pic_thumb.php

@@ -0,0 +1,121 @@
+<?php
+/**
+ * 上传表
+ */
+ 
+# 定义几个常用的选项
+$option = array
+(
+	1 => '启用',
+	2 => '关闭',
+);
+
+return array
+(
+	# 表名
+	'name' => 'pic_thumb',
+	# 显示给用户看的名称
+	'lang' => '缩略图配置',
+	//'menu' => false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '配置ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-24',
+			'name' 		=> '配置名',
+			'default' 	=> '',
+			'desc' 		=> '请输入配置名',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+		
+		'width'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '宽度',
+			'default' 	=> '0',
+			'desc' 		=> '请输入宽度',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+		
+		'height'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '高度',
+			'default' 	=> '0',
+			'desc' 		=> '请输入高度',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+		
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	# 默认值
+	/*
+	'default' => array
+	(
+		'col' => 'name,width,height,state,cdate',
+		'value' => array
+		(
+			'"660*330",660,330,1,' . time(),
+			'"330*165",330,165,1,' . time(),
+			'"1340*760",1340,760,1,' . time(),
+			'"420*420",420,420,1,' . time(),
+			'"300*140",300,140,1,' . time(),
+			'"580*230",580,230,1,' . time(),
+		),
+	),
+	*/
+
+	# request 请求接口定义
+	'request' => array
+	(
+		# info 取一条正常的数据
+		'info' => array
+		(
+			# 匹配的正则或函数 必填项
+			'where' => array
+			(
+				'id' => 'is_numeric',
+				'state' => 1,
+			),
+			'type' => 'one',
+		),
+	),
+);

+ 115 - 0
database/pic_water.php

@@ -0,0 +1,115 @@
+<?php
+/**
+ * 上传表
+ */
+ 
+# 定义几个常用的选项
+$option = array
+(
+	1 => '启用',
+	2 => '关闭',
+);
+
+$water = array
+(
+	1 => '左上',
+	2 => '左下',
+	3 => '右上',
+	4 => '右下',
+	5 => '居中',
+);
+
+return array
+(
+	# 表名
+	'name' => 'pic_water',
+	# 显示给用户看的名称
+	'lang' => '水印图配置',
+	//'menu' => false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '配置ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-24',
+			'name' 		=> '配置名',
+			'default' 	=> '',
+			'desc' 		=> '请输入配置名',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+		
+		'water'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '水印图',
+			'default' 	=> '',
+			'desc' 		=> '请选择水印图',
+			'match' 	=> 'option',
+			'update'	=> 'image',
+			'key' 		=> '1',
+			'place'		=> '150X150',
+		),
+		
+		'water_position'		=> array
+		(
+			'type' 		=> 'int-1',
+			'name' 		=> '水印图位置',
+			'default' 	=> '1',
+			'desc' 		=> '请选择水印图位置',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $water,
+			'update'	=> 'select',
+			//'list'		=> true,
+		),
+		
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	
+	# request 请求接口定义
+	'request' => array
+	(
+		# info 取一条正常的数据
+		'info' => array
+		(
+			# 匹配的正则或函数 必填项
+			'where' => array
+			(
+				'id' => 'is_numeric',
+				'state' => 1,
+			),
+			'type' => 'one',
+		),
+	),
+);

+ 158 - 0
database/upload.php

@@ -0,0 +1,158 @@
+<?php
+/**
+ * 上传表
+ */
+ 
+# 定义几个常用的选项
+$option = array
+(
+	1 => '启用',
+	2 => '关闭',
+);
+
+$cover = array
+(
+	1 => '覆盖原文件',
+	2 => '不覆盖,提示错误',
+	3 => '不覆盖,直接生成新文件',
+);
+
+return array
+(
+	# 表名
+	'name' => 'upload',
+	# 显示给用户看的名称
+	'lang' => '上传基本配置',
+	'order'	=> 10,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '配置ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-24',
+			'name' 		=> '配置名',
+			'default' 	=> '',
+			'desc' 		=> '请输入配置名',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+		
+		'width'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '限制宽度',
+			'default' 	=> '0',
+			'desc' 		=> '请输入宽度',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+		
+		'height'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '限制高度',
+			'default' 	=> '0',
+			'desc' 		=> '请输入高度',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+		
+		'size'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '限制大小(字节)',
+			'default' 	=> '0',
+			'desc' 		=> '请输入大小',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+		
+		'type'		=> array
+		(
+			'type' 		=> 'varchar-255',
+			'name' 		=> '限制文件后缀类型-多个用逗号隔开',
+			'default' 	=> '',
+			'desc' 		=> '请输入限制文件类型',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+		
+		'cover'		=> array
+		(
+			'type' 		=> 'int-1',
+			'name' 		=> '是否覆盖',
+			'default' 	=> '1',
+			'desc' 		=> '请选择是否覆盖',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $cover,
+			'update'	=> 'radio',
+			'list'		=> true,
+		),
+		
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	
+	# 默认值
+	'default' => array
+	(
+		'col' => 'name,cover,type,state,cdate',
+		'value' => array
+		(
+			'"默认图片配置",1,"jpg,png,gif",1,' . time(),
+			'"默认音频配置",1,"mp3",1,' . time(),
+			'"默认视频配置",1,"mp4",1,' . time(),
+			'"默认文件配置",1,"jpg,png,gif,doc,pdf,rar,zip,xls,xlsx,docx",1,' . time(),
+		),
+	),
+	
+	# request 请求接口定义
+	'request' => array
+	(
+		# info 取一条正常的数据
+		'info' => array
+		(
+			# 匹配的正则或函数 必填项
+			'where' => array
+			(
+				'id' => 'is_numeric',
+				'state' => 1,
+			),
+			'type' => 'one',
+		),
+	),
+);

+ 7 - 0
index.php

@@ -0,0 +1,7 @@
+<?php
+define('DEVER_APP_NAME', 'upload');
+define('DEVER_APP_LANG', '文件上传系统');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', -90);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-file');
+include(DEVER_APP_PATH . '../boot.php');

+ 75 - 0
src/Save.php

@@ -0,0 +1,75 @@
+<?php
+/*
+|--------------------------------------------------------------------------
+| 保存图片的几个方法
+|--------------------------------------------------------------------------
+*/
+namespace Upload\Src;
+
+use Dever;
+use Upload\Src\Store\Local as Handle;
+
+class Save
+{
+	public function __construct()
+	{
+		$image['file'] 	= Dever::input('file');
+		$image['key'] 	= Dever::input('key');
+		
+		//file_put_contents(DEVER_PATH . 'web/data/upload.txt', var_export($image, true)); 
+
+		$handle = new Handle($image);
+
+		$this->output = $handle->copy($image);
+		unset($this->output['file']);
+	}
+
+	public function action_api()
+	{
+		return $this->output;
+	}
+
+	public function start_api()
+	{
+		return $this->output;
+	}
+
+	public function drag_api()
+	{
+		if ($this->output['status'] == 1) {
+			$this->output['filename'] = $this->output['url'];
+		} else {
+			$this->output['error'] = $this->output['message'];
+		}
+		
+		Dever::outDiy($this->output);
+	}
+
+	public function ueditor_api()
+	{
+		if ($this->output['status'] == 1) {
+			$this->output['state'] = 'SUCCESS';
+			$this->output['original'] = 1;
+		} else {
+			$this->output['url'] = '';
+			$this->output['fileType'] = 1;
+			$this->output['original'] = 1;
+			$this->output['state'] = $this->output['message'];
+		}
+		
+		Dever::outDiy($this->output);
+	}
+
+	public function simditor_api()
+	{
+		if ($this->output['status'] == 1) {
+			$this->output['state'] = true;
+		} else {
+			$this->output['state'] = false;
+		}
+
+		$this->output['file_path'] = $this->output['url'];
+		
+		Dever::outDiy($this->output);
+	}
+}

+ 13 - 0
src/Store/Config.php

@@ -0,0 +1,13 @@
+<?php
+namespace Upload\Src\Store;
+
+interface Config
+{
+	public function save();
+
+	public function handle_w($water);
+
+	public function handle_t($id);
+
+	public function handle_c($id);
+}

+ 348 - 0
src/Store/Core.php

@@ -0,0 +1,348 @@
+<?php
+namespace Upload\Src\Store;
+
+use Dever;
+use Dever\String\Helper as String;
+use Dever\Loader\Config;
+
+class Core
+{
+	protected $data;
+
+	protected $config;
+
+	protected $handle;
+
+	protected $output;
+
+	protected $limit;
+
+	protected $name;
+
+	protected $path;
+
+	protected $ext;
+
+	protected $file;
+
+	protected $size;
+
+	protected $base = '';
+	
+	/**
+     * __construct
+     * 
+     * @return mixed
+     */
+	public function __construct($data)
+	{
+		$this->data = $data;
+	}
+
+	/**
+     * 获取根目录
+     * 
+     * @return mixed
+     */
+	protected function root()
+	{
+		if (!$this->base) {
+			$path = Config::data();
+			$this->base = $path . 'upload/';
+		}
+
+		return $this->base;
+	}
+	
+	/**
+     * 验证数据
+     * 
+     * @return mixed
+     */
+	private function check($param)
+	{
+		foreach ($param as $k => $v) {
+			$method = 'check_' . $v;
+			$this->$method();
+			
+			if ($this->output['status'] == -1) {
+				break;
+			}
+		}
+	}
+	
+	/**
+     * 验证key是否包含有后续处理的方法
+     * 
+     * @return mixed
+     */
+	private function check_handle()
+	{
+		if (isset($this->data['key']) && strpos($this->data['key'], '_') !== false) {
+			$temp = explode('_', $this->data['key']);
+			$this->data['key'] = $temp[0];
+			unset($temp[0]);
+			foreach ($temp as $k => $v) {
+				$this->handle[] = explode('=', $v);
+			}
+		}
+	}
+	
+	/**
+     * 验证文件是否存在
+     * 
+     * @return mixed
+     */
+	private function check_file()
+	{
+		if ($this->data['file']['tmp_name'] == '') {
+			$this->output['status'] = -1;
+			$this->output['message'] = '没有选择文件';
+		}
+	}
+	
+	/**
+     * 验证基本配置
+     * 
+     * @return mixed
+     */
+	private function check_key()
+	{
+		if (trim($this->data['key']) == '') {
+			$this->output['status'] = -1;
+			$this->output['message'] = '请添加配置key';
+		} else {
+			$this->config = Dever::load('upload/upload-one', $this->data['key']);
+			
+			if (!$this->config) {
+				$this->output['status'] = -1;
+				$this->output['message'] = '此配置不存在';
+			}
+		}
+	}
+	
+	/**
+     * 验证文件类型
+     * 
+     * @return mixed
+     */
+	private function check_type()
+	{
+		$ext = $this->getExt($this->data['file']['tmp_name']);
+		if (strpos($this->config['type'], $ext) === false) {
+			$this->output['status'] = -1;
+			$this->output['message'] = '文件格式不符合要求';
+		}
+
+		$this->ext = '.' . $ext;
+	}
+	
+	/**
+     * 验证文件大小
+     * 
+     * @return mixed
+     */
+	private function check_size()
+	{
+		if ($this->config['width'] > 0 || $this->config['height'] > 0) {
+			$this->limit = getimagesize($this->data['file']['tmp_name']);
+		}
+
+		# 默认30M
+		$size = $this->config['size'] > 0 ? 1024*$this->config['size'] : 30*1024*1024;
+
+		$this->size = $this->data['file']['size'];
+		
+		if (($size < $this->data['file']['size']) && $size > 0) {
+			$this->output['status'] = -1;
+			$this->output['message'] = '文件不能超过'.$size.'k';
+		} elseif ($this->config['width'] > 0 && $this->config['width'] < $this->limit[0]) {
+			$this->output['status'] = -1;
+			$this->output['message'] = '图片宽度不能超过' . $this->config['width'] . 'px';
+		} elseif ($this->config['height'] > 0 && $this->config['height'] < $this->limit[1]) {
+			$this->output['status'] = -1;
+			$this->output['message'] = '图片高度不能超过' . $this->config['height'] . 'px';
+		}
+	}
+	
+	/**
+     * 上传操作
+     * 
+     * @return mixed
+     */
+	public function copy()
+	{
+		$this->output['status'] = 1; 
+
+		if (is_string($this->data['file'])) {
+			if (strpos($this->data['file'], 'http') !== false) {
+				$this->output['status'] = -1;
+				$this->output['message'] = '暂时不支持复制网络文件';
+
+				return $this->output;
+			}
+
+			$this->root();
+
+			header('Content-type: text/json; charset=utf-8');
+
+			$file = base64_decode($this->data['file']);
+			$path = Dever::path($this->base . 'tmp/');
+			$this->data['file'] = array();
+			$this->data['file']['name'] = 'Tmp' . String::rand(8) . md5(microtime() . rand(0,1000)) . '.jpg';
+			$this->data['file']['tmp_name'] = $path . $this->data['file']['name'];
+			file_put_contents($this->data['file']['tmp_name'], $file);
+			$this->data['file']['size'] = filesize($this->data['file']['tmp_name']);
+		} else {
+			header("Content-type: application/json; charset=utf-8");
+		}
+
+		$this->check(array('handle', 'file', 'key', 'type', 'size'));
+
+		if ($this->output['status'] == -1) {
+			unlink($this->data['file']['tmp_name']);
+			return $this->output;
+		}
+		
+		$this->save();
+		
+		if ($this->output['status'] == -1) {
+			return $this->output;
+		}
+		
+		if (isset($this->handle) && is_array($this->handle)) {
+			foreach ($this->handle as $k => $v) {
+				$method = 'handle_' . $v[0];
+				$this->$method($v[1]);
+			}
+		}
+
+		$this->output['status'] = 1;
+		$this->output['name'] = $this->data['file']['name'];
+
+		return $this->output;
+	}
+
+	protected function update($id)
+	{
+		$param['set_name'] = $this->name;
+		$param['set_source_name'] = $this->data['file']['name'];
+		$param['set_file'] = $this->file;
+		$param['set_key'] = md5($this->output['url']);
+		$param['set_ext'] = $this->ext;
+
+		if ($this->limit) {
+			$param['set_width'] = $this->limit[0];
+			$param['set_height'] = $this->limit[1];
+		}
+		
+		if ($this->size) {
+			$param['set_size'] = $this->size;
+		}
+		
+		$param['where_id'] = $id;
+
+		Dever::load('upload/file-update', $param);
+	}
+
+	protected function insert()
+	{
+		$param['add_name'] = $this->name;
+		$param['add_source_name'] = $this->data['file']['name'];
+		$param['add_file'] = $this->file;
+		$param['add_key'] = md5($this->output['url']);
+		$param['add_ext'] = $this->ext;
+
+		if ($this->limit) {
+			$param['add_width'] = $this->limit[0];
+			$param['add_height'] = $this->limit[1];
+		}
+		
+		if ($this->size) {
+			$param['add_size'] = $this->size;
+		}
+		
+		$param['add_state'] = 1;
+
+
+		//file_put_contents(DEVER_PATH . 'data/test', var_export($param,true));
+
+		Dever::load('upload/file-insert', $param);
+	}
+	
+	/**
+     * getExt
+     * 
+     * @return mixed
+     */
+	protected function getExt($filename)
+	{
+		$file = fopen($filename,"rb");
+		$bin = fread($file,2);
+		fclose($file);
+		$strInfo = @unpack("c2chars",$bin);
+		$typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
+		$fileType = '';
+		switch ($typeCode) {
+			case 7790:
+				$fileType = 'exe';
+			break;
+			case 7784:
+				$fileType = 'midi';
+			break;
+			case 8297:
+				$fileType = 'rar';
+			break;
+			case 255216:
+				$fileType = 'jpg';
+			break;
+			case 7173:
+				$fileType = 'gif';
+			break;
+			case 13780:
+				$fileType = 'png';
+			break;
+			case 6677:
+				$fileType = 'bmp';
+			break;
+			case 6787:
+				$fileType = 'swf';
+			break;
+			case 6063;
+				$fileType = 'php|xml';
+			break;
+			case 6033:
+				$fileType = 'html|htm|shtml';
+			break;
+			case 8075:
+				$fileType = 'zip';
+			break;
+			case 6782:
+			case 1310:
+				$fileType = 'txt';
+			break;
+			case 4742:
+				$fileType = 'js';
+			break;
+			case 8273:
+				$fileType = 'wav';
+			break;
+			case 7368:
+				$fileType = 'mp3';
+			break;
+			default:
+				$fileType = 'unknown'.$typeCode;
+			break;
+		}
+		if ($strInfo['chars1'] == '-1' && $strInfo['chars2'] == '-40') {
+			return 'jpg';
+		}
+		if ($strInfo['chars1'] == '-119' && $strInfo['chars2'] == '80') {
+			return 'png';
+		}
+		if ($strInfo['chars1'] == '-48' && $strInfo['chars2'] == '-49') {
+			return 'msi';
+		}
+		return $fileType;
+	}
+}

+ 155 - 0
src/Store/Local.php

@@ -0,0 +1,155 @@
+<?php
+namespace Upload\Src\Store;
+
+use Dever;
+use Dever\Img\Handle;
+
+class Local extends Core implements Config
+{
+	/**
+     * 创建文件和目录
+     * 
+     * @return mixed
+     */
+	public function save()
+	{
+		$this->root();
+		
+		$this->path()->name($this->data['file']['name'])->ext()->file();
+		
+		# 不覆盖
+		if (is_file($this->output['file']) && $this->config['cover'] == 2) {
+			$this->output['status'] = -1;
+			$this->output['message'] = '文件已经存在';
+		} else {
+			# 不覆盖 生成新文件
+			if (is_file($this->output['file']) && $this->config['cover'] == 3) {
+				// . microtime() . rand(0,1000)
+				$this->name($this->output['file'])->file();
+			} else {
+				$file = Dever::load('upload/file-name', array('where_name' => $this->name));
+			}
+
+			if (!$this->limit) {
+				//$this->limit = getimagesize($this->output['file']);
+			}
+
+			if (!$this->size) {
+				$this->size = filesize($this->output['file']);
+			}
+			
+			if (isset($file) && $file) {
+				$this->update($file['id']);
+				
+			} else {
+				$this->insert();
+			}
+			
+			if (!copy($this->data['file']['tmp_name'], $this->output['file'])) {
+				$this->output['status'] = -1;
+				$this->output['message'] = '文件已经存在';
+			} else {
+				unlink($this->data['file']['tmp_name']);
+			}
+
+			return $this->output['url'];
+		}
+	}
+
+	private function path()
+	{
+		$date = explode('-', date("Y-m-d"));
+
+		$this->path = $this->config['id'] . '/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/';
+
+		return $this;
+	}
+
+	private function name($name)
+	{
+		$this->name = md5($name);
+
+		return $this;
+	}
+
+	private function ext()
+	{
+		$this->ext  = $this->ext ? $this->ext : '.' . pathinfo($this->data['file']['name'], PATHINFO_EXTENSION);
+
+		return $this;
+	}
+
+	private function file()
+	{
+		$this->file = $this->path . $this->name . $this->ext;
+
+		$this->output['file'] = is_file($this->base . $this->file) ? $this->base . $this->file : Dever::path($this->base, $this->file);
+		$this->output['url'] = Dever::config('host')->uploadRes . $this->file;
+
+		return $this->output['file'];
+	}
+
+	private function handle()
+	{
+		$this->handle = isset($this->handle) ? $this->handle : new Handle();
+
+		return $this->handle;
+	}
+	
+	/**
+     * water
+     * 
+     * @return mixed
+     */
+	public function handle_w($id)
+	{
+		$config = Dever::load('upload/pic_water-one', $id);
+		if ($config) {
+			$this->name .= '_w' . $id;
+			
+			$water = array('water'=> $config['water'], 'position'=> ($config['water_position'] ? $config['water_position'] : 1));
+			
+            $this->handle()->mark($this->output['file'], $water, true, $this->file());
+		}
+	}
+	
+	/**
+     * thumb
+     * 
+     * @return mixed
+     */
+	public function handle_t($id)
+	{
+		$config = Dever::load('upload/pic_thumb-one', $id);
+		if ($config) {
+			if (strpos($this->name, '_t') !== false) {
+				$temp = explode('_t', $this->name);
+				$this->name = $temp[0];
+			}
+			$this->name .= '_t' . $id;
+			
+			$size = $config['width'] . '_' . $config['height'] . '_2';
+			
+            $this->handle()->thumb($this->output['file'], $size, true, $this->file());
+		}
+	}
+	
+	/**
+     * crop
+     * 
+     * @return mixed
+     */
+	public function handle_c($id)
+	{
+		$config = Dever::load('upload/pic_crop-one', $id);
+		
+		if ($config) {
+			$this->name .= '_c' . $id;
+			
+			$size = $config['width'] . '_' . $config['height'] . '_2';
+			
+			//false position
+            $this->handle()->crop($this->output['file'], $size, false, true, $this->file());
+		}
+	}
+}