public function upload($savePath = '')
{
mkdir($savePath, 0777, true);
//如果不指定保存文件名,则由系统默认
if (empty($savePath)) {
$savePath = $this->savePath;
}
// 检查上传目录
if (!is_dir($savePath)) {
// 检查目录是否编码后的
if (is_dir(base64_decode($savePath))) {
$savePath = base64_decode($savePath);
} else {
// 尝试创建目录
if (!mkdir($savePath, 0777, true)) {
$this->error = '上传目录' . $savePath . '不存在';
return false;
}
}
} else {
if (!is_writable($savePath)) {
$this->error = '上传目录' . $savePath . '不可写';
return false;
}
}
$fileInfo = array();
$isUpload = false;
// 获取上传的文件信息
// 对$_FILES数组信息处理
$files = $this->dealFiles($_FILES);
foreach ($files as $key => $file) {
//过滤无效的上传
if (!empty($file['name'])) {
$file['key'] = $key;
$file['extension'] = $this->getExt($file['name']);
$file['savepath'] = $savePath;
$file['savename'] = uniqid() . substr(str_shuffle('0123456789abcdef'), rand(0, 9), 7) . '.' . $file['extension'];
//$this->getSaveName($file);
if ($GLOBALS['fromMobile'] == true && empty($file['extension'])) {
//移动设备上传的无后缀的图片,默认为jpg
$file['extension'] = 'jpg';
$file['savename'] = trim($file['savename'], '.') . '.jpg';
} else {
// 自动检查附件
if ($this->autoCheck) {
if (!$this->check($file)) {
return false;
}
}
}
//保存上传文件
if (!$this->save($file)) {
return false;
}
if (function_exists($this->hashType)) {
$fun = $this->hashType;
$file['hash'] = $fun(auto_charset($file['savepath'] . $file['savename'], 'utf-8', 'gbk'));
}
//上传成功后保存文件信息,供其它地方调用
unset($file['tmp_name'], $file['error']);
$fileInfo[] = $file;
$isUpload = true;
//图片上传裁剪
//$this->resetimg($savePath,$file['savename'],$file['save_Path']);
}
}
if ($isUpload) {
$this->uploadFileInfo = $fileInfo;
return true;
} else {
$this->error = '上传出错!文件不符合上传要求。';
return false;
}
}