private function save($file)
{
$filename = $file['savepath'] . $file['savename'];
if (!$this->config['replace'] && is_file($filename)) {
//不覆盖同名文件
$this->errorInfo = "文件已经存在{$filename}";
return false;
}
//如果是图片,检查格式
if (in_array(strtolower($file['extension']), ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf']) && false === getimagesize($file['tmp_name'])) {
$this->errorInfo = '非法图像文件';
return false;
}
if (!move_uploaded_file($file['tmp_name'], $filename)) {
$this->errorInfo = '文件上传错误!';
return false;
}
if ($this->config['thumb'] && in_array(strtolower($file['extension']), ['gif', 'jpg', 'jpeg', 'bmp', 'png'])) {
if ($image = getimagesize($filename)) {
//生成缩略图
$thumbPath = $this->config['thumbPath'] ? $this->config['thumbPath'] : dirname($filename);
$thunbName = $this->config['thumbFile'] ? $this->config['thumbFile'] : $this->config['thumbPrefix'] . basename($filename);
Image::makeThumb($filename, $thumbPath . '/' . $thunbName, null, $this->config['thumbMaxWidth'], $this->config['thumbMaxHeight']);
}
}
return true;
}