Skip to content

Commit

Permalink
Merge pull request #444 from sunnyos/master
Browse files Browse the repository at this point in the history
add uploadfile getFile method
  • Loading branch information
stelin authored Jun 24, 2019
2 parents fe27249 + 2e00b4b commit fe7e3a6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

> 日期时间都是大概的时间点
## 2019.06.24

- 添加文件上传获取文件信息 getFile (@sunny)

## 2019.04.29

- ws server 模块路由支持变量(@inhere)
Expand Down
6 changes: 0 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@
"branch-alias": {
}
},
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.laravel-china.org"
}
},
"scripts": {
"component": "php run.php -c phpunit.xml",
"aop": "php run.php -c src/aop/phpunit.xml",
Expand Down
36 changes: 36 additions & 0 deletions src/http-message/src/Upload/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class UploadedFile implements UploadedFileInterface
*/
private $moved;

/**
* @var string
*/
private $path;

/**
* @param string $tmpFile
* @param int $size
Expand Down Expand Up @@ -206,6 +211,19 @@ private function setFile(string $tmpFile): self
return $this;
}

/**
* @return array
*/
public function getFile()
{
return [
'size' => $this->getSize(),
'type' => $this->getClientMediaType(),
'file' => $this->getPath(),
'fileName' => $this->getClientFilename()
];
}

/**
* @return bool
*/
Expand Down Expand Up @@ -261,6 +279,23 @@ private function isStringNotEmpty($param): bool
return is_string($param) && false === empty($param);
}

/**
* @return string
*/
public function getPath(): string
{
return $this->path;
}

/**
* @param string $path
*/
public function setPath(string $path): void
{
$this->path = $path;
}


/**
* check file upload
*/
Expand All @@ -286,5 +321,6 @@ public function validateSavePath($targetPath)
throw new \RuntimeException("Cannot create directory");
}
}
$this->setPath($targetPath);
}
}

0 comments on commit fe7e3a6

Please sign in to comment.