-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
141 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace tourze\Base\Component; | ||
|
||
use tourze\Base\Component; | ||
use tourze\Base\Component\Upload\Entity; | ||
use tourze\Base\Helper\Arr; | ||
|
||
/** | ||
* 上传处理 | ||
* | ||
* @package tourze\Base\Component | ||
*/ | ||
class Upload extends Component implements UploadInterface | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public $persistence = false; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function get($name) | ||
{ | ||
if ( ! isset($_FILES[$name])) | ||
{ | ||
return false; | ||
} | ||
|
||
return new Entity([ | ||
'name' => Arr::get($_FILES[$name], 'name'), | ||
'type' => Arr::get($_FILES[$name], 'type'), | ||
'path' => Arr::get($_FILES[$name], 'tmp_name'), | ||
'error' => Arr::get($_FILES[$name], 'error', 0), | ||
'size' => Arr::get($_FILES[$name], 'size', 0), | ||
]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function all() | ||
{ | ||
return array_keys($_FILES); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace tourze\Base\Component\Upload; | ||
|
||
use tourze\Base\Object; | ||
|
||
/** | ||
* 单个上传文件的实例 | ||
* | ||
* @package tourze\Base\Component\Upload | ||
*/ | ||
class Entity extends Object | ||
{ | ||
|
||
/** | ||
* @var string 文件名 | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @var string 文件类型 | ||
*/ | ||
public $type; | ||
|
||
/** | ||
* @var string 文件路径 | ||
*/ | ||
public $path; | ||
|
||
/** | ||
* @var int 错误? | ||
*/ | ||
public $error = 0; | ||
|
||
/** | ||
* @var int 文件字节数 | ||
*/ | ||
public $size = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace tourze\Base\Component; | ||
|
||
use tourze\Base\Component\Upload\Entity; | ||
use tourze\Base\ComponentInterface; | ||
|
||
/** | ||
* 上传处理接口 | ||
* | ||
* @package tourze\Base\Component | ||
*/ | ||
interface UploadInterface extends ComponentInterface | ||
{ | ||
|
||
/** | ||
* 获取指定key的上传文件 | ||
* | ||
* @param string $name | ||
* @return bool|Entity | ||
*/ | ||
public function get($name); | ||
|
||
/** | ||
* 获取所有已经上传的文件 | ||
* | ||
* @return array | ||
*/ | ||
public function all(); | ||
} |