ASP上传代码? 在本机上调试成功,在网络上就不行了

来源:互联网 发布:深圳益玩网络 编辑:程序博客网 时间:2024/05/01 03:33

form action="" method="post">
<br>选择你要上传到的类别:<br>
<%
Set rs1 = conn.Execute("select * from ptype order by pid")
%>
<%
dim bb
bb=0
do while not rs1.eof
bb=bb+1
%>
<input name="pho" type="radio" value="<%=rs1("pid")%>" checked ><%=rs1("pname")%>
<%
if bb=5 then
response.write "<br><br>"
end if
rs1.movenext
loop
rs1.close

set rs1=nothing


%>
<input type="radio" name="pho" value="15">我的作品
<input type="radio" name="pho" value="16">别人的作品
<br><br>
相片介绍:
<input type="text" name="intr" size="30" >
<br>
<br>
你的名字:
<input type="text" name="name" size="15">
<p>文件名:<input name="f1" type="file" size="25" >
<input name="t1" type="submit" value="上传" > </p>
</form>
<br><br>
<p>           <a href="photo.asp">返回相册</a>

<% if request("t1")<>"" then
dim pho,nam,intro
pho = request.Form("pho")
nam = request.Form("name")
intr =request.form("intr")
dim a ,b,c,d
a=request("f1")
for i=1 to len(a)
b=mid(a,len(a)-i+1,1)
if b="/" then
exit for
end if
c=b+c
next
if a<>"" then
set fs=server.CreateObject("scripting.filesystemobject")
s1=a
t2=server.mappath("photo/"&c)
t3="photo/"&c

end if
dim sql
sql = "select * from photo"
set rs = server.CreateObject("adodb.recordset")
rs.open sql,conn,3,3
lld=rs("link")
unm=strcomp(lld,t3,1)
if unm<>0 then
fs.copyfile s1,t2,false
rs.addnew
rs("intro")=intr
rs("whichp")=pho
rs("name")=nam
rs("link")=t3
rs("date")=date()
rs.update
%>
msgbox"好消息:上传成功!!!"
你上传的文件是:<%=a%>
<% else
response.write "<br><br>"
%>
msbox"你上传的文件名已经存在,请重新命名文件"
<%end if %>
<%
rs.close
set rs=nothing
set conn=nothing
end if
%> 

确认你的空间是否支持FSO组件

---------------------------------
无组件上传(Up.asp)
---------------------------------
<%
dim Data_Upload

Class file_Upload

dim objForm,objFile

Public function Form(strForm)
strForm=lcase(strForm)
if not objForm.exists(strForm) then
Form=""
else
Form=objForm(strForm)
end if
End function

Public function File(strFile)
strFile=lcase(strFile)
if not objFile.exists(strFile) then
set File=new FileInfo
else
set File=objFile(strFile)
end if
End function


Private Sub Class_Initialize
dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
dim iFindStart,iFindEnd
dim iFormStart,iFormEnd,sFormName
set objForm=Server.CreateObject("Scripting.Dictionary")
set objFile=Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes<1 then Exit Sub
set tStream = Server.CreateObject("adodb.stream")
set Data_Upload = Server.CreateObject("adodb.stream")
Data_Upload.Type = 1
Data_Upload.Mode =3
Data_Upload.Open
Data_Upload.Write Request.BinaryRead(Request.TotalBytes)
Data_Upload.Position=0
RequestData =Data_Upload.Read

iFormStart = 1
iFormEnd = LenB(RequestData)
vbCrlf = chrB(13) & chrB(10)
sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
iStart = LenB (sStart)
iFormStart=iFormStart+iStart+1
while (iFormStart + 10) < iFormEnd
iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3
tStream.Type = 1
tStream.Mode =3
tStream.Open
Data_Upload.Position = iFormStart
Data_Upload.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sInfo = tStream.ReadText
tStream.Close
'取得表单项目名称
iFormStart = InStrB(iInfoEnd,RequestData,sStart)
iFindStart = InStr(22,sInfo,"name=""",1)+6
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
'如果是文件
if InStr (45,sInfo,"filename=""",1) > 0 then
set theFile=new FileInfo
'取得文件名
iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileName=getFileName(sFileName)
theFile.FilePath=getFilePath(sFileName)
'取得文件类型
iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr(iFindStart,sInfo,vbCr)
theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileStart =iInfoEnd
theFile.FileSize = iFormStart -iInfoEnd -3
theFile.FormName=sFormName
if not objFile.Exists(sFormName) then
objFile.add sFormName,theFile
end if
else
'如果是表单项目
tStream.Type =1
tStream.Mode =3
tStream.Open
Data_Upload.Position = iInfoEnd
Data_Upload.CopyTo tStream,iFormStart-iInfoEnd-3
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sFormValue = tStream.ReadText
tStream.Close
if objForm.Exists(sFormName) then
objForm(sFormName)=objForm(sFormName)&", "&sFormValue
else
objForm.Add sFormName,sFormValue
end if
end if
iFormStart=iFormStart+iStart+1
wend
RequestData=""
set tStream =nothing
End Sub

Private Sub Class_Terminate
if Request.TotalBytes>0 then
objForm.RemoveAll
objFile.RemoveAll
set objForm=nothing
set objFile=nothing
Data_Upload.Close
set Data_Upload =nothing
end if
End Sub


Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "/"))
Else
GetFilePath = ""
End If
End function

Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "/")+1)
Else
GetFileName = ""
End If
End function
End Class

Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileType,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
FileType = ""
End Sub

Public function UploadFileName()
Dim lngTime,strDate
strDate=replace(cstr(Date()),"-","")
lngTime=clng(timer()*1000)
lngTime=lngTime+1
UploadFileName=strDate&lngTime
FileName=Mid(FileName,instr(FileName,"."))
UploadFileName=UploadFileName&FileName
End function


Public function SaveAs(FullPath)
dim dr,ErrorChar,i,SaveFileName
SaveAs=true
if trim(fullpath)="" or FileStart=0 or FileName="" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
Data_Upload.position=FileStart
Data_Upload.copyto dr,FileSize
dr.SaveToFile Server.MapPath(FullPath),2
dr.Close
set dr=nothing
SaveAs=false
End function

End Class
%>


--------------------------
上传文件处理页面
--------------------------
<!--#include file="Up.asp"-->
<%
...
myPath="" '设置你要上传到的文件夹位置
set file=upLoad.file("filePath")
if file.FileSize>0 then
file.SaveAs myPath & file.UploadFileName
....
%>