【asp源码栏目提醒】:以下是网学会员为您推荐的asp源码-asp实现上传功能的源 - 开发文档,希望本篇文章对您学习有所帮助。
Wwp
asp无组件上传图片的
源码分析及下载 要实现图片的上传功能其实非常简单只需要四个文件与一个文件夹即可实现。
第一个文件Upload.
asp 这个文件的源代码如下 说明这个文件将引用一个名为upload_Photo.
asp的文件也就是下面要讲的第二个文件作为框架同时这里传递一个PhotoUrlID参数给pload_Photo.
asp这个文件的form1表单中的名为PhotoUrlID的隐藏域名其值为1 第二个文件Upload_Photo.
asp这个文件的源代码如下 说明这个是作为第一个文件Upload.
asp的框架文件注意这里的FileName的文本框是用于接受上传成功之后图片的地址 第三个文件Upfile_Photo.
asp其源代码如下 0 then 如果出错 select case upload.err case 1 response.write 请先选择你要上传的文件 case 2 response.write 你上传的文件总大小超出了最大限制200k end select response.end end if PhotoUrlIDClngtrimupload.formPhotoUrlID if PhotoUrlID0 then SavePath UploadFiles 存放上传文件的目录 else SavePath UploadFiles 存放上传文件的目录 end if if rightSavePath1/ then SavePathSavePath/ 在目录后加/ for each formName in upload.file 列出所有上传了的文件 set ofileupload.fileformName 生成一个文件对象 oFileSizeofile.filesize if oFileSizeMaxFileSize1024 then msg文件大小超过了限制最大只能上传 CStrMaxFileSize K的文件 FoundErrtrue end if case 1 if oFileSize100001024 then msg文件大小超过了限制最大只能上传10M的文件 FoundErrtrue end if end select end if fileExtlcaseofile.FileExt arrUpFileTypesplitgifjpgbmppngswfdocrarxls如需添加其它类型的文档请在这里添加文档后缀名 for i0 to uboundarrUpFileType if fileEXTtrimarrUpFileTypei then EnableUploadtrue exit for end if next if fileEXTasp or fileEXTasa or fileEXTaspx then EnableUploadfalse end if if EnableUploadfalse then msg这种文件类型不允许上传nn只允许上传这几种文件类型 gifjpgbmppngswfdocrarxls FoundErrtrue end if strJS vbcrlf response.write strJS set filenothing next set uploadnothing end sub 第四个文件upfile_class.
asp源代码如下 0 Then 如果限制大小 If Request.TotalBytes MaxSize Then Err 2 如果上传的数据超出限制 Exit Sub End If End If Set Form Server.CreateObject Scripting.Dictionary Form.CompareMode 1 Set File Server.CreateObject Scripting.Dictionary File.CompareMode 1 Set tStream Server.CreateObject ADODB.Stream Set oUpFileStream Server.CreateObject ADODB.Stream oUpFileStream.Type 1 oUpFileStream.Mode 3 oUpFileStream.Open oUpFileStream.Write Request.BinaryRead Request.TotalBytes oUpFileStream.Position 0 RequestBinData oUpFileStream.Read iFormEnd oUpFileStream.Size bCrLf ChrB 13 ChrB 10 取得每个项目之间的分隔符 sSpace MidB RequestBinData1 InStrB 1RequestBinDatabCrLf-1 iStart LenB sSpace iFormStart iStart2 分解项目 Do iInfoEnd InStrB iFormStartRequestBinDatabCrLf bCrLf3 tStream.Type 1 tStream.Mode 3 tStream.Open oUpFileStream.Position iFormStart oUpFileStream.CopyTo tStreamiInfoEnd-iFormStart tStream.Position 0 tStream.Type 2 tStream.CharSet gb2312 sInfo tStream.ReadText 取得表单项目名称 iFormStart InStrB iInfoEndRequestBinDatasSpace-1 iFindStart InStr 22sInfoname16 iFindEnd InStr iFindStartsInfo1 sFormName Mid sinfoiFindStartiFindEnd-iFindStart 如果是文件 If InStr 45sInfofilename1 0 Then Set oFileInfo new FileInfo_Class 取得文件属性 iFindStart InStr iFindEndsInfofilename110 iFindEnd InStr iFindStartsInfo1 sFileName Mid sinfoiFindStartiFindEnd-iFindStart oFileInfo.FileName Mid sFileNameInStrRev sFileName 1 oFileInfo.FilePath Left sFileNameInStrRev sFileName oFileInfo.FileExt Mid sFileNameInStrRev sFileName .1 iFindStart InStr iFindEndsInfoContent-Type: 114 iFindEnd InStr iFindStartsInfovbCr oFileInfo.FileType Mid sinfoiFindStartiFindEnd-iFindStart oFileInfo.FileStart iInfoEnd oFileInfo.FileSize iFormStart -iInfoEnd -2 oFileInfo.FormName sFormName file.add sFormNameoFileInfo else 如果是表单项目 tStream.Close tStream.Type 1 tStream.Mode 3 tStream.Open oUpFileStream.Position iInfoEnd oUpFileStream.CopyTo tStreamiFormStart-iInfoEnd-2 tStream.Position 0 tStream.Type 2 tStream.CharSet gb2312 sFormValue tStream.ReadText If Form.Exists sFormName Then Form sFormName Form sFormName sFormValue else form.Add sFormNamesFormValue End If End If tStream.Close iFormStart iFormStartiStart2 如果到文件尾了就退出 Loop Until iFormStart2 iFormEnd RequestBinData Set tStream Nothing End Sub End Class ------------------------------------------------------------------------------ 文件属性类 Class FileInfo_Class Dim FormNameFileNameFilePathFileSizeFileTypeFileStartFileExt 保存文件方法 Public Function SaveToFile Path if lcaserightPath3lcaseFileExt then 经典的上传漏洞_ response.Write response.end end if On Error Resume Next Dim oFileStream Set oFileStream CreateObject ADODB.Stream oFileStream.Type 1 oFileStream.Mode 3 oFileStream.Open oUpFileStream.Position FileStart oUpFileStream.CopyTo oFileStreamFileSize oFileStream.SaveToFile Path2 oFileStream.Close Set oFileStream Nothing End Function 取得文件数据 Public Function FileData oUpFileStream.Position FileStart FileData oUpFileStream.Read FileSize End Function End Class 除了上面四个文件夹之外还需要一个名为UploadFiles的文件夹注意以上的四个文件与文件夹都是放在网站根目录下也就是同极目录下的如果目录不同级请修改路径同时本程序不仅可以包括jpgpnggif等类型的图片还可以上传word、EXECL、记事本、RAR压缩包等当然上传对大小是有限的只限定在200K以内如果超过200K将会出错. Wwp
上一篇:
ASP程序容错技术及其实现机制
下一篇:
投简历到国外的公司需考虑哪些东西?