Skip to content

Commit

Permalink
移除文件大小限制
Browse files Browse the repository at this point in the history
  • Loading branch information
moxuandi committed Dec 22, 2019
1 parent ef9a09a commit 00d68dc
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 22 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ echo Helper::getFullName('img.jpg', 'uploads/image/{yyyy}{mm}/{time}');
### Uploader上传类用法示例:
```php
$config = [
'maxSize' => 1*1024*1024, // 上传大小限制, 单位B, 默认1MB
'allowFiles' => ['.png', '.jpg', '.jpeg', '.gif', '.bmp'], // 上传图片格式显示
'pathFormat' => 'uploads/image/{yyyy}{mm}/{yy}{mm}{dd}_{hh}{ii}{ss}_{rand:4}', // 上传保存路径, 可以自定义保存路径和文件名格式
'modelClass' => 'common\model\Upload', // 文件信息是否保存入库
Expand Down
21 changes: 0 additions & 21 deletions Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Uploader
/**
* @var array 上传配置信息
* 可用的数组的键如下:
* - `maxSize`: int 上传大小限制, 默认为: 1*1024*1024 (1M).
* - `allowFiles`: array 允许上传的文件类型, 默认为: ['.png', '.jpg', '.jpeg']. 设置为空数组或`false`时, 将不验证文件类型!
* - `pathFormat`: string 文件保存路径, 默认为: '/uploads/image/{time}'.
* - `realName`: string 图片的原始名称, 处理 base64 编码的图片时有效.
Expand Down Expand Up @@ -141,7 +140,6 @@ class Uploader
public function __construct($fileField, $config = [], $type = 'upload')
{
$_config = [
'maxSize' => 1*1024*1024, // 上传大小限制, 单位B, 默认1MB
'allowFiles' => ['.png', '.jpg', '.jpeg'], // 上传图片格式显示
'pathFormat' => '/uploads/image/{time}', // 上传保存路径
'realName' => 'scrawl.png', // base64 编码的图片的默认名称
Expand Down Expand Up @@ -207,12 +205,6 @@ public function uploadFile()
return false;
}

// 检查文件大小是否超出网站限制
if($this->file->size > $this->config['maxSize']){
$this->status = 'ERROR_SIZE_EXCEED';
return false;
}

$this->realName = $this->file->name;
$this->fileSize = $this->file->size;
$this->fileType = $this->file->type;
Expand Down Expand Up @@ -295,12 +287,6 @@ public function uploadChunkFile()
'percent' => round($post['chunk'] / $post['chunks'] * 100) . '%',
];

// 检查文件大小是否超出网站限制
if($this->fileSize > $this->config['maxSize']){
$this->status = 'ERROR_SIZE_EXCEED';
return false;
}

// 检查文件类型(扩展名)是否符合网站要求
if($this->config['allowFiles'] && !in_array('.' . $this->fileExt, $this->config['allowFiles'])){
$this->status = 'ERROR_TYPE_NOT_ALLOWED';
Expand Down Expand Up @@ -371,12 +357,6 @@ public function uploadBase64($fileField)
$this->fullName = Helper::getFullName($this->realName, $this->config['pathFormat'], $this->fileExt);
$this->fileName = StringHelper::basename($this->fullName);

// 检查文件大小是否超出网站限制
if($this->fileSize > $this->config['maxSize']){
$this->status = 'ERROR_SIZE_EXCEED';
return false;
}

// 创建目录
$fullPath = FileHelper::normalizePath($this->rootPath . DIRECTORY_SEPARATOR . $this->fullName); // 文件在磁盘上的绝对路径
if(!FileHelper::createDirectory(dirname($fullPath))){
Expand Down Expand Up @@ -672,7 +652,6 @@ public function saveDatabase($fullPath = null)
8 => '因 php 扩展停止文件上传', // UPLOAD_ERR_EXTENSION
//'ERROR_TMP_FILE' => '临时文件错误',
'ERROR_TMP_FILE_NOT_FOUND' => '找不到临时文件',
'ERROR_SIZE_EXCEED' => '文件大小超出网站限制',
'ERROR_TYPE_NOT_ALLOWED' => '文件类型不允许',
'ERROR_CREATE_DIR' => '目录创建失败',
'ERROR_DIR_NOT_WRITEABLE' => '目录没有写入权限',
Expand Down

0 comments on commit 00d68dc

Please sign in to comment.