Skip to content

Commit

Permalink
改进File类
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Nov 11, 2018
1 parent 00f4d4c commit f36634f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions library/think/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,10 @@ public function checkMime($mime)
* @param string $path 保存路径
* @param string|bool $savename 保存的文件名 默认自动生成
* @param boolean $replace 同名文件是否覆盖
* @param bool $autoAppendExt 自动补充扩展名
* @return false|File false-失败 否则返回File实例
*/
public function move($path, $savename = true, $replace = true)
public function move($path, $savename = true, $replace = true, $autoAppendExt = true)
{
// 文件上传失败,捕获错误代码
if (!empty($this->info['error'])) {
Expand All @@ -357,7 +358,7 @@ public function move($path, $savename = true, $replace = true)

$path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
// 文件保存命名规则
$saveName = $this->buildSaveName($savename);
$saveName = $this->buildSaveName($savename, $autoAppendExt);
$filename = $path . $saveName;

// 检测目录
Expand Down Expand Up @@ -391,9 +392,10 @@ public function move($path, $savename = true, $replace = true)
* 获取保存文件名
* @access protected
* @param string|bool $savename 保存的文件名 默认自动生成
* @param bool $autoAppendExt 自动补充扩展名
* @return string
*/
protected function buildSaveName($savename, $auto_ext = true)
protected function buildSaveName($savename, $autoAppendExt = true)
{
if (true === $savename) {
// 自动生成文件名
Expand All @@ -403,7 +405,7 @@ protected function buildSaveName($savename, $auto_ext = true)
$savename = $this->getInfo('name');
}

if ($auto_ext && false === strpos($savename, '.')) {
if ($autoAppendExt && false === strpos($savename, '.')) {
$savename .= '.' . pathinfo($this->getInfo('name'), PATHINFO_EXTENSION);
}

Expand Down

0 comments on commit f36634f

Please sign in to comment.