请给个无组件上传文件的Asp代码 并且说明怎么更改上传到的目录 和上传后的文件路径以及制作
2个回答
展开全部
dim ExtName,SavePath,UpLoadAll_a,UploadStream_c,FormDataAll_d,CrLf_e,FormStart_f,FormEnd_g,FormStream_h,FormStreamText_i,FileName_j, SaveFile
ExtName = "jpg,gif,png" '允许扩展名
SavePath = "/pic" '保存路径
If Right(SavePath,1)<>"/" Then SavePath=SavePath&"/" '在目录后加(/)
CheckAndCreateFolder(SavePath)
UpLoadAll_a = Request.TotalBytes '取得客户端全部内容
If(UpLoadAll_a>0) Then
If(UpLoadAll_a<=1024*2000) Then'=======================此处限制图片大小小于200KB=========================
Set UploadStream_c = Server.CreateObject("ADODB.Stream")
UploadStream_c.Type = 1
UploadStream_c.Open
UploadStream_c.Write Request.BinaryRead(UpLoadAll_a)
UploadStream_c.Position = 0
FormDataAll_d = UploadStream_c.Read
CrLf_e = chrB(13)&chrB(10)
FormStart_f = InStrB(FormDataAll_d,CrLf_e)
FormEnd_g = InStrB(FormStart_f+1,FormDataAll_d,CrLf_e)
Set FormStream_h = Server.Createobject("ADODB.Stream")
FormStream_h.Type = 1
FormStream_h.Open
UploadStream_c.Position = FormStart_f + 1
UploadStream_c.CopyTo FormStream_h,FormEnd_g-FormStart_f-3
FormStream_h.Position = 0
FormStream_h.Type = 2
FormStream_h.CharSet = "gb2312" '这里是上传文件时候使用的编码
FormStreamText_i = FormStream_h.Readtext
FormStream_h.Close
dim newname
randomize
newname = year(now())&month(now())&day(now())&hour(now())&cint(8999*Rnd+1000)&cint(8999*Rnd+1000) '这里是定义一个新的文件名称 我这里按照 年月日小时和一个随机函数组成
FileName_j = newname &"."& Mid(FormStreamText_i,InstrRev(FormStreamText_i,".")+1,FormEnd_g) '这里是上面的新文件名和文件原来的扩展名组成完成的文件名
If(CheckFileExt(FileName_j,ExtName)) Then '这里是判断文件名是否重复
SaveFile = Server.MapPath(SavePath & FileName_j)
Err.Clear
If Err Then
response.Write("<script>alert('系统出错!');</script>")
Err.Clear
Else
SaveFile = CheckFileExists(SaveFile)
dim k,l,SaveFileName
k=Instrb(FormDataAll_d,CrLf_e&CrLf_e)+4
l=Instrb(k+1,FormDataAll_d,leftB(FormDataAll_d,FormStart_f-1))-k-2
FormStream_h.Type=1
FormStream_h.Open
UploadStream_c.Position=k-1
UploadStream_c.CopyTo FormStream_h,l
FormStream_h.SaveToFile SaveFile,2
SaveFileName = Mid(SaveFile,InstrRev(SaveFile,"\")+1)
session("picpath") = "/pic/" & SaveFileName '我这里是把刚才上传完成的文件路径赋值给了一个session 方便另外的页面掉用
session("picpath") = ""
response.Write("<script>alert('保存成功!');window.location='edit_banner.asp '</script>")
End If
Else
response.Write("<script>alert('图片格式不正确!');</script>")
End If
Else
'=====================此处为提示文件大小超过了=========================
response.Write("<script>alert('图片太大!');</script>")
End If
end if
自己看看再研究研究吧 这个是直接从我原来的代码里面复制的
ExtName = "jpg,gif,png" '允许扩展名
SavePath = "/pic" '保存路径
If Right(SavePath,1)<>"/" Then SavePath=SavePath&"/" '在目录后加(/)
CheckAndCreateFolder(SavePath)
UpLoadAll_a = Request.TotalBytes '取得客户端全部内容
If(UpLoadAll_a>0) Then
If(UpLoadAll_a<=1024*2000) Then'=======================此处限制图片大小小于200KB=========================
Set UploadStream_c = Server.CreateObject("ADODB.Stream")
UploadStream_c.Type = 1
UploadStream_c.Open
UploadStream_c.Write Request.BinaryRead(UpLoadAll_a)
UploadStream_c.Position = 0
FormDataAll_d = UploadStream_c.Read
CrLf_e = chrB(13)&chrB(10)
FormStart_f = InStrB(FormDataAll_d,CrLf_e)
FormEnd_g = InStrB(FormStart_f+1,FormDataAll_d,CrLf_e)
Set FormStream_h = Server.Createobject("ADODB.Stream")
FormStream_h.Type = 1
FormStream_h.Open
UploadStream_c.Position = FormStart_f + 1
UploadStream_c.CopyTo FormStream_h,FormEnd_g-FormStart_f-3
FormStream_h.Position = 0
FormStream_h.Type = 2
FormStream_h.CharSet = "gb2312" '这里是上传文件时候使用的编码
FormStreamText_i = FormStream_h.Readtext
FormStream_h.Close
dim newname
randomize
newname = year(now())&month(now())&day(now())&hour(now())&cint(8999*Rnd+1000)&cint(8999*Rnd+1000) '这里是定义一个新的文件名称 我这里按照 年月日小时和一个随机函数组成
FileName_j = newname &"."& Mid(FormStreamText_i,InstrRev(FormStreamText_i,".")+1,FormEnd_g) '这里是上面的新文件名和文件原来的扩展名组成完成的文件名
If(CheckFileExt(FileName_j,ExtName)) Then '这里是判断文件名是否重复
SaveFile = Server.MapPath(SavePath & FileName_j)
Err.Clear
If Err Then
response.Write("<script>alert('系统出错!');</script>")
Err.Clear
Else
SaveFile = CheckFileExists(SaveFile)
dim k,l,SaveFileName
k=Instrb(FormDataAll_d,CrLf_e&CrLf_e)+4
l=Instrb(k+1,FormDataAll_d,leftB(FormDataAll_d,FormStart_f-1))-k-2
FormStream_h.Type=1
FormStream_h.Open
UploadStream_c.Position=k-1
UploadStream_c.CopyTo FormStream_h,l
FormStream_h.SaveToFile SaveFile,2
SaveFileName = Mid(SaveFile,InstrRev(SaveFile,"\")+1)
session("picpath") = "/pic/" & SaveFileName '我这里是把刚才上传完成的文件路径赋值给了一个session 方便另外的页面掉用
session("picpath") = ""
response.Write("<script>alert('保存成功!');window.location='edit_banner.asp '</script>")
End If
Else
response.Write("<script>alert('图片格式不正确!');</script>")
End If
Else
'=====================此处为提示文件大小超过了=========================
response.Write("<script>alert('图片太大!');</script>")
End If
end if
自己看看再研究研究吧 这个是直接从我原来的代码里面复制的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询