= 2) { $ext = "." . $filename_component[count($filename_component)-1]; } if (array_key_exists($ext, Mimetype::map)) { $mimetype = Mimetype::map[$ext]; } else if (function_exists('mime_content_type')) { $mimetype = mime_content_type($filename); } else if (function_exists('finfo_file')) { $finfo = finfo_open(FILEINFO_MIME_TYPE); // 返回 mime 类型 $mimetype = finfo_file($finfo, $filename); finfo_close($finfo); } else { return array("application/octet-stream", null); } return array($mimetype, null); } function Header_Get($header, $key) { $val = @$header[$key]; if (isset($val)) { if (is_array($val)) { return $val[0]; } return $val; } else { return ''; } } function ResponseError($resp) { $header = $resp->Header; $err = new Error($resp->StatusCode, null); if ($err->Code > 299) { if ($resp->ContentLength !== 0) { if (Header_Get($header, 'Content-Type') === 'application/json') { $ret = json_decode($resp->Body, true); $err->ErrRet = $ret['ErrRet']; $err->ErrMsg = $ret['ErrMsg']; } } } $err->Reqid = Header_Get($header, 'X-SessionId'); return $err; } function CheckConfig($auth, $action) { switch ($action) { case ActionType::PUTFILE: case ActionType::POSTFILE: case ActionType::MINIT: case ActionType::MUPLOAD: case ActionType::MCANCEL: case ActionType::MFINISH: case ActionType::DELETE: case ActionType::UPLOADHIT: if ($auth->ProxySuffix == "") { return new Error(400, -1, "no proxy suffix found in config"); } else if ($auth->PublicKey == "" || strstr($auth->PublicKey, " ") != FALSE) { return new Error(400, -1, "invalid public key found in config"); } else if ($auth->PrivateKey == "" || strstr($auth->PrivateKey, " ") != FALSE) { return new Error(400, -1, "invalid private key found in config"); } break; case ActionType::GETFILE: if ($auth->ProxySuffix == "") { return new Error(400, -1, "no proxy suffix found in config"); } break; default: break; } return null; } }