老a论坛官网:关于asp无惧上传类的一个问题
来源:百度文库 编辑:神马品牌网 时间:2024/08/25 04:10:46
上传类用的是动网中的。Upfile.inc和Class_UpFile.asp,我看了一下,连oblog也用的是动网的类,所以决定按他们的模式来写。。。
表单代码:
<div s="width:420px;margin:auto;">
<form method="post" name="UpLoadForm" id="UpLoadForm" action="ModifyUserInfo.asp?Action=SaveUserPhoto" enctype="multipart/form-data" onsubmit="return checkUpfiles()">
div class="up1">
<input class="upinput" type="text" name="tempUpLoadFile" id="tempUpLoadFile" size="35">
</div>
<div>
<input type="image" src="Images/Q_UPhoto01.gif" s="width:52px;height:18px;" onclick="UpLoadForm.UpLoadFile.click()">
<input name="btnSubmit" id="btnSubmit" type="image" src="Images/Q_UPhoto02.gif" s="width:52px;height:18px;" onclick="uploading.style.display=(uploading.style.display=='none'?'':'none');btnDisabled();">
<input name="UpLoadFile" type="file" id="UpLoadFile" onchange="UpLoadForm.tempUpLoadFile.value=this.value" s="display:none;">
<input type="hidden" name="UploadCode" value="<%=PostRanNum%>">
</div>
</form>
</div>
上传部分
Function SaveUserPhoto()
Server.ScriptTimeOut=9999999
Dim Upload,UpFileType,FilePath,FileSize,File,FormName,F_FileName
UpFileType = "jpg|gif" '设置上传文件类型
FilePath = "Love/UserPhoto/" '设置文件保存相对路径
FileSize = 100 '设置上传文件大小,以kb为单位
UpFileType = Replace(UpFileType,"|",",")
Set Upload = New UpFile_Cls
Upload.UploadType = 0 '设置上传类型 0 - 无组件上传
Upload.UploadPath = FilePath
Upload.MaxSize = Int(FileSize)
Upload.InceptMaxFile = 1 '同时上传文件数量
Upload.InceptFileType = UpFileType
Upload.RName = ""
Upload.ChkSessionName = "UploadCode"
Upload.PreviewType = 999 '设置水印组件类型 999 - 无
Upload.SaveUpFile '开始执行上传
If Upload.Count > 0 Then
For Each FormName In Upload.UploadFiles
Set File = Upload.UploadFiles(FormName)
F_FileName = FilePath & File.FileName
Set File = Nothing
Next
End If
If Upload.ErrCodes <> 0 Then
Set Upload = Nothing
Session("SysNum") = 23
Response.Redirect("SystemMsg.asp")
Response.End
Exit Function
End If
Set Upload = Nothing
End Function
现在运行以后,出现错误号7,查了一下Class_UpFile类里错误号7描述是Session内容不正确。
另外把类里有关Session的判断去掉以后,又出现错误号5,没有上传内容。
我用response.write Upload.UploadFiles(FormName) 列出,居然FormName是空的。。
不知何故。
我自己解决了。
表单代码:
<div s="width:420px;margin:auto;">
<form method="post" name="UpLoadForm" id="UpLoadForm" action="ModifyUserInfo.asp?Action=SaveUserPhoto" enctype="multipart/form-data" onsubmit="return checkUpfiles()">
div class="up1">
<input class="upinput" type="text" name="tempUpLoadFile" id="tempUpLoadFile" size="35">
</div>
<div>
<input type="image" src="Images/Q_UPhoto01.gif" s="width:52px;height:18px;" onclick="UpLoadForm.UpLoadFile.click()">
<input name="btnSubmit" id="btnSubmit" type="image" src="Images/Q_UPhoto02.gif" s="width:52px;height:18px;" onclick="uploading.style.display=(uploading.style.display=='none'?'':'none');btnDisabled();">
<input name="UpLoadFile" type="file" id="UpLoadFile" onchange="UpLoadForm.tempUpLoadFile.value=this.value" s="display:none;">
<input type="hidden" name="UploadCode" value="<%=PostRanNum%>">
</div>
</form>
</div>
上传部分
Function SaveUserPhoto()
Server.ScriptTimeOut=9999999
Dim Upload,UpFileType,FilePath,FileSize,File,FormName,F_FileName
UpFileType = "jpg|gif" '设置上传文件类型
FilePath = "Love/UserPhoto/" '设置文件保存相对路径
FileSize = 100 '设置上传文件大小,以kb为单位
UpFileType = Replace(UpFileType,"|",",")
Set Upload = New UpFile_Cls
Upload.UploadType = 0 '设置上传类型 0 - 无组件上传
Upload.UploadPath = FilePath
Upload.MaxSize = Int(FileSize)
Upload.InceptMaxFile = 1 '同时上传文件数量
Upload.InceptFileType = UpFileType
Upload.RName = ""
Upload.ChkSessionName = "UploadCode"
Upload.PreviewType = 999 '设置水印组件类型 999 - 无
Upload.SaveUpFile '开始执行上传
If Upload.Count > 0 Then
For Each FormName In Upload.UploadFiles
Set File = Upload.UploadFiles(FormName)
F_FileName = FilePath & File.FileName
Set File = Nothing
Next
End If
If Upload.ErrCodes <> 0 Then
Set Upload = Nothing
Session("SysNum") = 23
Response.Redirect("SystemMsg.asp")
Response.End
Exit Function
End If
Set Upload = Nothing
End Function
现在运行以后,出现错误号7,查了一下Class_UpFile类里错误号7描述是Session内容不正确。
另外把类里有关Session的判断去掉以后,又出现错误号5,没有上传内容。
我用response.write Upload.UploadFiles(FormName) 列出,居然FormName是空的。。
不知何故。
我自己解决了。
Session的判断怎么能去掉啊?#
看看类里的内容!
难啊。。