Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
revert(UploadFile): Add back some attributes of UploadFile
Browse files Browse the repository at this point in the history
Add back the tmpName,size attributes of UploadFile, It once remove
because those attributes can fetch by SplFileInfo::getPathname() ,
SplFileInfo::getSize()
  • Loading branch information
Rhilip committed Feb 2, 2019
1 parent 26d3902 commit f6f9e6c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion framework/Http/UploadFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ class UploadFile extends SplFileInfo
// MIME类型
public $type;

// 临时文件名
public $tmpName;

// 错误码
public $error;

// 文件尺寸
public $size;

/**
* 创建实例,通过表单名称
* @param $name
Expand All @@ -36,7 +42,9 @@ public function __construct($file)
parent::__construct($file['tmp_name']);
$this->name = $file['name'];
$this->type = $file['type'];
$this->tmpName = $file['tmp_name'];
$this->error = $file['error'];
$this->size = $file['size'];
}

// 文件另存为
Expand All @@ -46,7 +54,7 @@ public function saveAs($filename)
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
$bytes = file_put_contents($filename, file_get_contents($this->getPathname()));
$bytes = file_put_contents($filename, file_get_contents($this->tmpName));
return $bytes ? true : false;
}

Expand All @@ -61,4 +69,10 @@ public function getExtension()
{
return pathinfo($this->name)['extension'];
}

// 获取文件内容
public function getFileContent()
{
return file_get_contents($this->tmpName);
}
}

0 comments on commit f6f9e6c

Please sign in to comment.