*/ require_once 'globals.php'; require_once "qiniu/io.php"; require_once "qiniu/rs.php"; $DB = Database::getInstance(); //上传表单显示 if ($action == 'selectFile') { $attachnum = 0; $logid = isset($_GET['logid']) ? intval($_GET['logid']) : ''; $multi = isset($_GET['multi']) ? intval($_GET['multi']) : 0; if ($logid) { $Log_Model = new Log_Model(); $row = $Log_Model->getOneLogForAdmin($logid); $attachnum = (int) $row['attnum']; } $maxsize = changeFileSize(Option::getAttMaxSize()); //允许附件类型 $att_type_str = ''; $att_type_for_muti = ''; foreach (Option::getAttType() as $val) { $att_type_str .= " {$val}"; $att_type_for_muti .= '*.' . $val . ';'; } $view_tpl = $multi ? 'upload_multi' : 'upload'; require_once View::getView($view_tpl); View::output(); } //上传附件 if ($action == 'upload') { $logid = isset($_GET['logid']) ? intval($_GET['logid']) : ''; $attach = isset($_FILES['attach']) ? $_FILES['attach'] : '';
/** * 文件上传 * * 返回的数组索引 * mime_type 文件类型 * size 文件大小(单位KB) * file_path 文件路径 * width 宽度 * height 高度 * 可选值(仅在上传文件是图片且系统开启缩略图时起作用) * thum_file 缩略图的路径 * thum_width 缩略图宽度 * thum_height 缩略图高度 * thum_size 缩略图大小(单位KB) * * @param string $fileName 文件名 * @param string $errorNum 错误码:$_FILES['error'] * @param string $tmpFile 上传后的临时文件 * @param string $fileSize 文件大小 KB * @param array $type 允许上传的文件类型 * @param boolean $isIcon 是否为上传头像 * @param boolean $is_thumbnail 是否生成缩略图 * @return array 文件数据 索引 * */ function upload($fileName, $errorNum, $tmpFile, $fileSize, $type, $isIcon = false, $is_thumbnail = true) { if ($errorNum == 1) { return '100'; //文件大小超过系统限制 } elseif ($errorNum > 1) { return '101'; //上传文件失败 } $extension = getFileSuffix($fileName); if (!in_array($extension, $type)) { return '102'; //错误的文件类型 } if ($fileSize > Option::getAttMaxSize()) { return '103'; //文件大小超出emlog的限制 } $file_info = array(); $file_info['file_name'] = $fileName; $file_info['mime_type'] = get_mimetype($extension); $file_info['size'] = $fileSize; $file_info['width'] = 0; $file_info['height'] = 0; $uppath = Option::UPLOADFILE_PATH . gmdate('Ym') . '/'; $fname = substr(md5($fileName), 0, 4) . time() . '.' . $extension; $attachpath = $uppath . $fname; $file_info['file_path'] = $attachpath; if (!is_dir(Option::UPLOADFILE_PATH)) { @umask(0); $ret = @mkdir(Option::UPLOADFILE_PATH, 0777); if ($ret === false) { return '104'; //创建文件上传目录失败 } } if (!is_dir($uppath)) { @umask(0); $ret = @mkdir($uppath, 0777); if ($ret === false) { return '105'; //上传失败。文件上传目录(content/uploadfile)不可写 } } doAction('attach_upload', $tmpFile); // 生成缩略图 $thum = $uppath . 'thum-' . $fname; if ($is_thumbnail) { if ($isIcon && resizeImage($tmpFile, $thum, Option::ICON_MAX_W, Option::ICON_MAX_H)) { $file_info['thum_file'] = $thum; $file_info['thum_size'] = filesize($thum); $size = getimagesize($thum); if ($size) { $file_info['thum_width'] = $size[0]; $file_info['thum_height'] = $size[1]; } resizeImage($tmpFile, $uppath . 'thum52-' . $fname, 52, 52); } elseif (resizeImage($tmpFile, $thum, Option::get('att_imgmaxw'), Option::get('att_imgmaxh'))) { $file_info['thum_file'] = $thum; $file_info['thum_size'] = filesize($thum); $size = getimagesize($thum); if ($size) { $file_info['thum_width'] = $size[0]; $file_info['thum_height'] = $size[1]; } } } if (@is_uploaded_file($tmpFile)) { if (@(!move_uploaded_file($tmpFile, $attachpath))) { @unlink($tmpFile); return '105'; //上传失败。文件上传目录(content/uploadfile)不可写 } @chmod($attachpath, 0777); } // 如果附件是图片需要提取宽高 if (in_array($file_info['mime_type'], array('image/jpeg', 'image/png', 'image/gif', 'image/bmp'))) { $size = getimagesize($file_info['file_path']); if ($size) { $file_info['width'] = $size[0]; $file_info['height'] = $size[1]; } } return $file_info; }