/** +---------------------------------------------------------- * 上传一个文件 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param mixed $name 数据 * @param string $value 数据表名 +---------------------------------------------------------- * @return string +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ private function save($file) { $filename = $file['savepath'] . $file['savename']; if (!$this->uploadReplace && is_file($filename)) { // 不覆盖同名文件 $this->error = '文件已经存在!' . $filename; return false; } // 如果是图像文件 检测文件格式 if (in_array(strtolower($file['extension']), array('gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf'))) { $info = getimagesize($file['tmp_name']); if (false === $info || 'gif' == strtolower($file['extension']) && empty($info['bits'])) { $this->error = '非法图像文件'; return false; } } if ($this->isFtp) { import('ORG.Net.Ftp'); $ftp = new Ftp($this->ftpHost, $this->ftpUser, $this->ftpPwd); if (!$ftp->save($filename, $file['tmp_name'])) { $this->error = $ftp->error; return false; } } elseif (!move_uploaded_file($file['tmp_name'], $this->autoCharset($filename, 'utf-8', 'gbk'))) { $this->error = '文件上传保存错误!'; return false; } if ($this->thumb && in_array(strtolower($file['extension']), array('gif', 'jpg', 'jpeg', 'bmp', 'png'))) { $image = getimagesize($filename); if (false !== $image) { //是图像文件生成缩略图 $thumbWidth = explode(',', $this->thumbMaxWidth); $thumbHeight = explode(',', $this->thumbMaxHeight); $thumbPrefix = explode(',', $this->thumbPrefix); $thumbSuffix = explode(',', $this->thumbSuffix); $thumbFile = explode(',', $this->thumbFile); $thumbPath = $this->thumbPath ? $this->thumbPath : dirname($filename) . '/'; // 生成图像缩略图 import($this->imageClassPath); //$realFilename = $this->autoSub?basename($file['savename']):$file['savename']; for ($i = 0, $len = count($thumbWidth); $i < $len; $i++) { $thumbname = $thumbPath . $thumbPrefix[$i] . basename($filename, '.' . $file['extension']) . $thumbSuffix[$i] . '.' . $file['extension']; Image::thumb($filename, $thumbname, '', $thumbWidth[$i], $thumbHeight[$i], true); } if ($this->thumbRemoveOrigin) { // 生成缩略图之后删除原图 unlink($filename); } } } if ($this->zipImags) { // TODO 对图片压缩包在线解压 } return true; }