如何把URL和邮件地址转换为超级链接?

Function InsertHyperlinks(inText)Dim objRegExp, strBufDim objMatches,
objMatchDim Value, ReplaceValue, iStart, iEnd strBuf = “” iStart = 1
iEnd = 1 Set objRegExp = New RegExp objRegExp.Pattern =
“/b(www|http|/S+@)/S+/b”

然而有些情况只需要传递几个文件,而且文件体积并不太大,这种情况下使用组件则有点牛刀杀鸡的感觉,通过html自带的表单就可以实现需要的功能,关键在于后台接收程序的处理。
php处理上传做的很方便,上传文件的信息通过服务器自动处理到$_FILES数组中,开发者只需要使用的内置处理函数简单操作就可以啦。ASP开发者则没有这么幸运,官方并没有提供直接的处理方法,需要开发者自己设计,这时就需要开发者了解IIS对enctype=”multipart/form-data”表单的处理方式,IIS把enctype=”multipart/form-data”表单提交的数据存储成二进制数据,以二进制格式返回给开发者,开发者则需要通过LenB、MidB的字节处理函数来分析获取的上传内容,客户端发送的具体表单数据格式,可以了解下HTTP
RFC1867协议传输格式方面的知识。
下面是我处理多个文件上传的方法,包括php和asp两个版本。
php:WEBSITE_DIRROOT代表网站根目录: 复制代码 代码如下: up_name = $name; !empty &&
$this->up_ext = $ext; $this->up_rename = $rename;
$this->up_dir = WEBSITE_DIRROOT. $GLOBALS[‘cfg_upload_path’];
$this->InitUpload(); } else {
exit(‘upload文件域名称为空,初始化失败!’); } } private function
InitUpload() { if (is_array($_FILES[澳门新葡亰3522平台游戏,$this->up_name])) { $up_arr
= count($_FILES[$this->up_name]); $up_all =
count($_FILES[$this->up_name], 1); $up_cnt = / $up_arr; for ($i
= 0; $i < $up_cnt; $i ++) { if
($_FILES[$this->up_name][‘error’][$i] != 4) {
$this->up_files[] = array( ‘tmp_name’ =>
$_FILES[$this->up_name][‘tmp_name’][$i], ‘name’ =>
$_FILES[$this->up_name][‘name’][$i], ‘type’ =>
$_FILES[$this->up_name][‘type’][$i], ‘size’ =>
$_FILES[$this->up_name][‘size’][$i], ‘error’ =>
$_FILES[$this->up_name][‘error’][$i] ); } } $this->up_num
= count; } else { if (isset($_FILES[$this->up_name])) {
$this->up_files = array( ‘tmp_name’ =>
$_FILES[$this->up_name][‘tmp_name’], ‘name’ =>
$_FILES[$this->up_name][‘name’], ‘type’ =>
$_FILES[$this->up_name][‘type’], ‘size’ =>
$_FILES[$this->up_name][‘size’], ‘error’ =>
$_FILES[$this->up_name][‘error’] ); $this->up_num = 1; }
else { exit; } } $this->ChkUpload(); } private function ChkUpload() {
if { $up_mime = array(‘image/wbmp’, ‘image/bmp’, ‘image/gif’,
‘image/pjpeg’, ‘image/x-png’); foreach ($this->up_files as
$up_file) { $up_allw = false; foreach { if ($up_file[‘type’] ==
$mime) { $up_allw = true; break; } } !$up_allw &&
exit(‘不允许上传’.$up_file[‘type’].’格式的文件!’); if
($up_file[‘size’] / 1024 > $this->up_max) {
exit(‘不允许上传大于 ‘.$this->up_max.’K 的文件!’); } } } else {
foreach ($this->up_files as $up_file) { $up_ext = end(explode(‘.’,
$up_file[‘name’])); $up_allw = false; foreach ($this->up_ext as
$ext) { if { $up_allw = true; break; } } !$up_allw &&
exit(‘不允许上传.’.$up_ext.’格式的文件!’); if ($up_file[‘size’] /
1024 > $this->up_max) { exit(‘不允许上传大于
‘.$this->up_max.’K 的文件!’); } } } $this->Uploading(); }
private function Uploading() { if (IO::DIRCreate { if (chmod { if
(!empty { foreach ($this->up_files as $up_file) { if
(is_uploaded_file) { $file_name = $up_file[‘name’]; if {
$file_ext = end(explode; $file_rnd = substr, mt_rand; $file_name =
date.’_’.$file_rnd.’.’.$file_ext; } $file_name =
$this->up_dir.’/’.$file_name; if
(move_uploaded_file($up_file[‘tmp_name’], $file_name)) {
$this->up_ret[] = str_replace(WEBSITE_DIRROOT, ”, $file_name);
} else { exit; } } } } } else { exit; } } else { exit; } } public
function GetUpload() { return empty ? false : $this->up_ret; }
function __destruct() {} } ?> asp: 复制代码 代码如下: dataLen Then partLen =
dataLen – curRead streamTmp.Write Request.BinaryRead curRead = curRead +
partLen LetProgress appName, Array(curRead, dataLen, DateDiff,
folderPath) Loop streamTmp.Position = 0 formData = streamTmp.Read
streamTmp.Close Set streamTmp = Nothing Call ItemPosition End Function
Private Function LetProgress(byVal sName, byVal vArr) Application.Value
= Join End Function Private Function DelProgress
Application.Contents.Remove(“PROGRESS” & IPToNum End Function Private
Function ItemPosition Dim iStart, iLength : iStart = 1 Do Until
InStrB(iStart, formData, bSeparate) = 0 iStart = InStrB(iStart,
formData, bSeparate) + LenB + 14 iLength = InStrB(iStart, formData,
bSeparate) – iStart – 2 If Abs(iStart + 2 – LenB > 2 Then ReDim
Preserve itemStart ReDim Preserve itemLength itemStart = iStart
itemLength = iLength itemCount = itemCount + 1 End If Loop Call
FillItemValue End Function Private Function FillItemValue Dim dataPart,
bInfor Dim iStart : iStart = 1 Dim iCount : iCount = 0 Dim iCheck :
iCheck = StrToByte For i = 0 To itemCount – 1 ReDim Preserve itemName
ReDim Preserve itemData ReDim Preserve extenArr ReDim Preserve httpArr
ReDim Preserve dataStart ReDim Preserve dataLength dataPart =
MidB(formData, itemStart iStart = InStrB) + 1 iLength = InStrB(iStart,
dataPart, ChrB – iStart itemName = GetItemName(MidB(dataPart, iStart,
iLength)) iStart = InStrB + 4 iLength = LenB – iStart + 1 If InStrB >
0 Then bInfor = MidB(dataPart, 1, iStart – 5) extenArr = FileExtenName
httpArr = GetHttpContent If IsNothing Then itemData = “” dataStart = “”
dataLength = “” Else If Mid(folderPath, Len = “/” Then If fRename Then
itemData = folderPath & GetRandomName Else itemData = folderPath &
GetClientName & extenArr End If Else If fRename Then itemData =
folderPath & “/” & GetRandomName Else itemData = folderPath & “/” &
GetClientName & extenArr End If End If dataStart = itemStart + iStart –
2 dataLength = iLength End If Else extenArr = “” httpArr = “” itemData =
ByteToStr(MidB(dataPart, iStart, iLength)) dataStart = “” dataLength =
“” End If iCount = iCount + 1 Next Call ItemToColl End Function Private
Function GetItemName GetItemName = ByteToStr End Function Private
Function ItemToColl For i = 0 To itemCount – 1 If Not Form.Exists Then
Form.Add itemName End If Next End Function Private Function
FileExtenName Dim pContent, regEx pContent = GetClientPath If IsNothing
Then FileExtenName = “” Else Set regEx = New RegExp regEx.Pattern =
“^.+$” regEx.Global = False regEx.IgnoreCase = True FileExtenName =
regEx.Replace Set regEx = Nothing End If End Function Private Function
GetHttpContent Dim sInfor, regEx sInfor = ByteToStr Set regEx = New
RegExp regEx.Pattern = “^[Ss]+Content-Type:$” regEx.Global = False
regEx.IgnoreCase = True GetHttpContent = Trim(regEx.Replace Set regEx =
Nothing End Function Private Function GetRandomName Dim regEx, sTemp,
arrFields, n : n = 0 Set regEx = New RegExp regEx.Pattern = “[^d]+”
regEx.Global = True regEx.IgnoreCase = True sTemp = regEx.Replace & “-”
Set regEx = Nothing arrFields = Array(“0”, “1”, “2”, “3”, “4”, “5”, “6”,
“7”, “8”, “9”, _ “a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, _
“k”, “l”, “m”, “n”, “o”, “p”, “q”, “r”, “s”, “t”, _ “u”, “v”, “w”, “x”,
“y”, “z”, “A”, “B”, “C”, “D”, _ “E”, “F”, “G”, “H”, “I”, “J”, “K”, “L”,
“M”, “N”, _ “O”, “P”, “Q”, “R”, “S”, “T”, “U”, “V”, “W”, “X”, _ “Y”,
“Z”) Randomize Do While n < sLen sTemp = sTemp & CStr n = n + 1 Loop
GetRandomName = sTemp End Function Private Function GetClientName Dim
pContent, regEx pContent = GetClientPath If IsNothing Then GetClientName
= “” Else Set regEx = New RegExp regEx.Pattern = “^.*\[^\]+$”
regEx.Global = False regEx.IgnoreCase = True GetClientName =
regEx.Replace Set regEx = Nothing End If End Function Private Function
GetClientPath Dim sInfor, pStart, pLength, pContent sInfor = ByteToStr
pStart = InStr(1, sInfor, “filename=” & Chr + 10 pLength = InStr(pStart,
sInfor, Chr – pStart pContent = Mid(sInfor, pStart, pLength)
GetClientPath = pContent End Function Public Function SaveUploadFile Dim
isValidate Dim filePath, oStreamGet, oStreamPut isValidate = fPassed And
CheckFile If isValidate Then For i = 0 To itemCount – 1 If Not IsNothing
And Not IsNothing Then If dataLength = 0 Then itemData = “” Else
filePath = Server.MapPath If CreateFolder(“|”, ParentFolder Then Set
oStreamGet = Server.CreateObject oStreamGet.Type = 1 oStreamGet.Mode = 3
oStreamGet.Open oStreamGet.Write formData oStreamGet.Position =
dataStart Set oStreamPut = Server.CreateObject oStreamPut.Type = 1
oStreamPut.Mode = 3 oStreamPut.Open oStreamPut.Write oStreamGet.Read
oStreamPut.SaveToFile filePath, 2 oStreamGet.Close Set oStreamGet =
Nothing oStreamPut.Close Set oStreamPut = Nothing End If End If End If
Next IsFinished = True Else IsFinished = False End If End Function
Private Function CheckFile Dim oBoolean : oBoolean = True CheckFile =
oBoolean And CheckType And CheckSize End Function Private Function
CheckType Dim oBoolean : oBoolean = True If fileType = “*” Then
oBoolean = oBoolean And True Else For i = 0 To itemCount – 1 If Not
IsNothing Then If InStr(1, fileType, “|” & Ucase & “|”) > 0 Then If
fIMGOnly Then Dim sAllow : sAllow = “|GIF|PJPEG|X-PNG|BMP|” Dim aCheck :
aCheck = Split, “/”) Dim iCheck : iCheck = “|” & aCheck & “|” If InStr
> 0 Then oBoolean = oBoolean And True Else sErrors = sErrors & “表单
[ ” & itemName & ” ] 的文件格式错误!n” & _ “支持的格式为:” &
Replace(Mid(fileType, 2, Len, “|”, ” “) & “nn” oBoolean = oBoolean
And False End If Else oBoolean = oBoolean And True End If Else sErrors =
sErrors & “表单 [ ” & itemName & ” ] 的文件格式错误!n” & _
“支持的格式为:” & Replace(Mid(fileType, 2, Len, “|”, ” “) & “nn”
oBoolean = oBoolean And False End If End If Next End If CheckType =
oBoolean End Function Private Function CheckSize Dim oBoolean : oBoolean
= True If fileSize = “*” Then oBoolean = oBoolean And True Else For i =
0 To itemCount – 1 If Not IsNothing Then Dim tmpSize : tmpSize =
CDbl(FormatNumber / 1024, 2)) If tmpSize <= fileSize Then oBoolean =
oBoolean And True Else sErrors = sErrors & “表单 [ ” & itemName & ” ]
的文件大小 超出范围!n” & _ “支持大小范围:<= ” & fileSize & ”
KBnn” oBoolean = oBoolean And False End If End If Next End If
CheckSize = oBoolean End Function Private Function CreateFolder(byVal
sLine, byVal sPath) Dim oFso Set oFso =
Server.CreateObject(“Scripting.FileSystemObject”) If Not
oFso.FolderExists Then Dim regEx Set regEx = New RegExp regEx.Pattern =
“^$” regEx.Global = False regEx.IgnoreCase = True sLine = sLine &
regEx.Replace & “|” sPath = regEx.Replace If CreateFolder Then
CreateFolder = True Set regEx = Nothing Else If sLine = “|” Then
CreateFolder = True Else Dim sTemp : sTemp = Mid – 2) If InStrRev = 0
Then sLine = “|” sPath = sPath & “” & sTemp Else Dim Folder : Folder =
Mid(sTemp, InStrRev sLine = “|” & Mid(sTemp, 1, InStrRev & “|” sPath =
sPath & “” & Folder End If oFso.CreateFolder sPath If CreateFolder
Then CreateFolder = True End if End If Set oFso = Nothing End Function
Private Function ParentFolder Dim regEx Set regEx = New RegExp
regEx.Pattern = “^\[^\]*$” regEx.Global = True regEx.IgnoreCase
= True ParentFolder = regEx.Replace Set regEx = Nothing End Function
Private Function IsNothing IsNothing = CBool End Function Private
Function StrPadLeft(byVal sText, byVal sLen, byVal sChar) Dim sTemp :
sTemp = sText Do While Len < sLen : sTemp = sChar & sTemp : Loop
StrPadLeft = sTemp End Function Private Function StrToByte For i = 1 To
Len StrToByte = StrToByte & ChrB) Next End Function Private Function
ByteToStr Dim oStream Set oStream = Server.CreateObject oStream.Type = 2
oStream.Mode = 3 oStream.Open oStream.WriteText sByte oStream.Position =
0 oStream.CharSet = “gb2312” oStream.Position = 2 ByteToStr =
oStream.ReadText oStream.Close Set oStream = Nothing End Function
Private Function GetClientIPAddr If
IsNothing(GetServerVar(“HTTP_X_FORWARDED_FOR”)) Then GetClientIPAddr
= GetServerVar Else GetClientIPAddr =
GetServerVar(“HTTP_X_FORWARDED_FOR”) End If End Function Private
Function GetServerVar GetServerVar = Request.ServerVariables End
Function Private Function IPToNum Dim sIp_1, sIp_2, sIp_3, sIp_4 If
IsNumeric Then sIp_1 = Left – 1) sIp = Mid + 1) sIp_2 = Left – 1) sIp
= Mid + 1) sIp_3 = Left – 1) sIp_4 = Mid + 1) End If IPToNum = CInt *
256 * 256 * 256 + CInt * 256 * 256 + CInt * 256 + CInt – 1 End
Function REM CLASS-TERMINATE Private Sub Class_Terminate Call
DelProgress Form.RemoveAll Set Form = Nothing End Sub End Class %>

‘ 判断URLs和emails. objRegExp.IgnoreCase = True

‘ 设置大小写不敏感.. objRegExp.Global = True