(500分)求ASP或PHP网页上传文件代码.
求ASP或PHP网页上传文件代码.就是把一些(如zip.rar.exe)文件利用网页上传到空间里去.代码不需要太多,只需要几个,越少越好,只要能用,我给500分.上传完成...
求ASP或PHP网页上传文件代码.
就是把一些(如zip.rar.exe)文件利用网页上传到空间里去.
代码不需要太多,只需要几个,越少越好,只要能用,我给500分.
上传完成后一定要提示连接地址. 展开
就是把一些(如zip.rar.exe)文件利用网页上传到空间里去.
代码不需要太多,只需要几个,越少越好,只要能用,我给500分.
上传完成后一定要提示连接地址. 展开
展开全部
asp
==============================================================
<%OPTION EXPLICIT%>
<%Server.ScriptTimeOut=5000%>
<!--#include FILE="upload_5xsoft.inc"-->
<html>
<head>
<title>文件上传</title>
</head>
<body>
<br>化境文件上传!<hr size=1 noshadow width=300 align=left><br><br>
<%
dim upload,file,formName,formPath,iCount
set upload=new upload_5xsoft ''建立上传对象
response.write upload.Version&"<br><br>"? ''显示上传类的版本
if upload.form("filepath")="" then?? ''得到上传目录
? HtmEnd "请输入要上传至的目录!"
? set upload=nothing
? response.end
else
? formPath=upload.form("filepath")
? ''在目录后加(/)
? if right(formPath,1)<>"/" then formPath=formPath&"/"
end if
iCount=0
for each formName in upload.objForm ''列出所有form数据
? response.write formName&"="&upload.form(formName)&"<br>"
next
response.write "<br>"
for each formName in upload.objFile ''列出所有上传了的文件
? set file=upload.file(formName)? ''生成一个文件对象
? if file.FileSize>0 then???????? ''如果 FileSize > 0 说明有文件数据
? file.SaveAs Server.mappath(formPath&file.FileName)?? ''保存文件
? response.write file.FilePath&file.FileName&" ("&file.FileSize&") => "&formPath&File.FileName&" 成功!<br>"
? iCount=iCount+1
? end if
? set file=nothing
next
set upload=nothing? ''删除此对象
Htmend iCount&" 个文件上传结束!"
sub HtmEnd(Msg)
? set upload=nothing
? response.write "<br>"&Msg&" [<a href=""javascript:history.back();"">返回</a>]</body>< /html>"
? response.end
end sub
%>
</body>
</html>
==============================================================
<%OPTION EXPLICIT%>
<%Server.ScriptTimeOut=5000%>
<!--#include FILE="upload_5xsoft.inc"-->
<html>
<head>
<title>文件上传</title>
</head>
<body>
<br>化境文件上传!<hr size=1 noshadow width=300 align=left><br><br>
<%
dim upload,file,formName,formPath,iCount
set upload=new upload_5xsoft ''建立上传对象
response.write upload.Version&"<br><br>"? ''显示上传类的版本
if upload.form("filepath")="" then?? ''得到上传目录
? HtmEnd "请输入要上传至的目录!"
? set upload=nothing
? response.end
else
? formPath=upload.form("filepath")
? ''在目录后加(/)
? if right(formPath,1)<>"/" then formPath=formPath&"/"
end if
iCount=0
for each formName in upload.objForm ''列出所有form数据
? response.write formName&"="&upload.form(formName)&"<br>"
next
response.write "<br>"
for each formName in upload.objFile ''列出所有上传了的文件
? set file=upload.file(formName)? ''生成一个文件对象
? if file.FileSize>0 then???????? ''如果 FileSize > 0 说明有文件数据
? file.SaveAs Server.mappath(formPath&file.FileName)?? ''保存文件
? response.write file.FilePath&file.FileName&" ("&file.FileSize&") => "&formPath&File.FileName&" 成功!<br>"
? iCount=iCount+1
? end if
? set file=nothing
next
set upload=nothing? ''删除此对象
Htmend iCount&" 个文件上传结束!"
sub HtmEnd(Msg)
? set upload=nothing
? response.write "<br>"&Msg&" [<a href=""javascript:history.back();"">返回</a>]</body>< /html>"
? response.end
end sub
%>
</body>
</html>
展开全部
不只是一个文件而已.
<!--#include file="setup.asp"-->
<!--#include file="upfile_class.asp"-->
<%
dim db,connstr
db="#data.asp"
set Conn = server.CreateObject("ADODB.Connection")
connstr="driver={Microsoft Access Driver (*.mdb)};dbq="& server.MapPath("data/"&db&"")
conn.Open connstr
const upload_type=0 '上传方法:0=无惧无组件上传类,1=FSO上传 2=lyfupload,3=aspupload,4=chinaaspupload
Const MaxFileSize=100 '上传文件大小限制
Const SaveUpFilesPath="adpic" '存放上传文件的目录
Const UpFileType="gif|jpg|bmp" '允许的上传文件类型
dim upload,oFile,formName,SavePath,filename,fileExt,oFileSize
dim EnableUpload
dim arrUpFileType
dim ranNum
dim msg,FoundErr
dim PhotoUrlID
msg=""
FoundErr=false
EnableUpload=false
id=request("id")
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
BODY{
BACKGROUND-COLOR: #E1F4EE;
font-size:9pt
}
.tx1 { height: 20px;font-size: 9pt; border: 1px solid; border-color: #000000; color: #0000FF}
-->
</style>
</head>
<body leftmargin="2" topmargin="5" marginwidth="0" marginheight="0" >
<%
if EnableUploadFile="No" then
response.write "系统未开放文件上传功能"
else
if session("china_uid")="" and session("china_cityadmin") and session("china_admin")="" then
response.Write("请登录后再使用本功能!")
else
select case upload_type
case 0
call upload_0() '使用化境无组件上传类
case else
'response.write "本系统未开放插件功能"
'response.end
end select
end if
end if
%>
</body>
</html>
<%
sub upload_0() '使用化境无组件上传类
set upload=new upfile_class ''建立上传对象
upload.GetData(104857600) '取得上传数据,限制最大上传100M
if upload.err > 0 then '如果出错
select case upload.err
case 1
response.write "请先选择你要上传的文件!"
case 2
response.write "你上传的文件总大小超出了最大限制(100M)"
end select
response.end
end if
PhotoUrlID=Clng(trim(upload.form("PhotoUrlID")))
if PhotoUrlID>0 then
SavePath = SaveUpFilesPath '存放上传文件的目录
else
SavePath = SaveUpFilesPath '存放上传文件的目录
end if
if right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)
set rs=Server.CreateObject("adodb.recordset")
rs.Open "select * from upfile",conn,1,3
for each formName in upload.file '列出所有上传了的文件
set ofile=upload.file(formName) '生成一个文件对象
oFileSize=ofile.filesize
if oFileSize<100 then
msg="请先选择你要上传的文件!"
FoundErr=True
else
select case PhotoUrlID
case 0
if oFileSize>(MaxFileSize*1024) then
msg="文件大小超过了限制,最大只能上传" & CStr(MaxFileSize) & "K的文件!"
FoundErr=true
end if
case 1
if oFileSize>(10000*1024) then
msg="文件大小超过了限制,最大只能上传10M的文件!"
FoundErr=true
end if
end select
end if
fileExt=lcase(ofile.FileExt)
arrUpFileType=split(UpFileType,"|")
for i=0 to ubound(arrUpFileType)
if fileEXT=trim(arrUpFileType(i)) then
EnableUpload=true
exit for
end if
next
if fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" then
EnableUpload=false
end if
if EnableUpload=false then
msg="这种文件类型不允许上传!\n\n只允许上传这几种文件类型:" & UpFileType
FoundErr=true
end if
strJS="<SCRIPT language=javascript>" & vbcrlf
if FoundErr<>true then
randomize
ranNum=int(900*rnd)+100
picname=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
filename=SavePath&picname
ofile.SaveToFile Server.mappath(FileName) '保存文件
rs.AddNew
rs("filename")=picname
rs("username")=session("china_uid")
rs.Update
response.write "文件上传成功!文件大小为:" & cstr(round(oFileSize/1024)) & "K"
select case PhotoUrlID
case 0
strJS=strJS & "parent.document.postart.dpic.value='" & picname & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize1.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 1
strJS=strJS & "parent.document.myform.DownloadUrl.value='" & fileName & "';" & vbcrlf
strJS=strJS & "parent.document.myform.FileSize.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 2
response.redirect "admin/link_img.asp?id="&id&"&web="&picname
'strJS=strJS & "parent.document.myform.PhotoUrl2.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize2.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 3
strJS=strJS & "parent.document.myform.CompVisualize.value='" & fileName & "';" & vbcrlf
' strJS=strJS & "parent.document.myform.PhotoSize3.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 4
strJS=strJS & "parent.document.myform.PhotoUrl4.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize4.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 5
strJS=strJS & "parent.document.myform.CompHonor.value='" & fileName & "';" & vbcrlf
' strJS=strJS & "parent.document.myform.PhotoSize5.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 6
strJS=strJS & "parent.document.myform.DefaultPicUrl.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize6.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 7
strJS=strJS & "parent.document.myform.MovieAddr.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize6.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
end select
else
strJS=strJS & "alert('" & msg & "');" & vbcrlf
strJS=strJS & "history.go(-1);" & vbcrlf
end if
strJS=strJS & "</script>" & vbcrlf
response.write strJS
if PhotoUrlID=1 then
response.redirect "admin/ad.asp?id="&id&"&picname="&picname
end if
set file=nothing
next
rs.close
set rs=nothing
set upload=nothing
end sub
%>
<!--#include file="setup.asp"-->
<!--#include file="upfile_class.asp"-->
<%
dim db,connstr
db="#data.asp"
set Conn = server.CreateObject("ADODB.Connection")
connstr="driver={Microsoft Access Driver (*.mdb)};dbq="& server.MapPath("data/"&db&"")
conn.Open connstr
const upload_type=0 '上传方法:0=无惧无组件上传类,1=FSO上传 2=lyfupload,3=aspupload,4=chinaaspupload
Const MaxFileSize=100 '上传文件大小限制
Const SaveUpFilesPath="adpic" '存放上传文件的目录
Const UpFileType="gif|jpg|bmp" '允许的上传文件类型
dim upload,oFile,formName,SavePath,filename,fileExt,oFileSize
dim EnableUpload
dim arrUpFileType
dim ranNum
dim msg,FoundErr
dim PhotoUrlID
msg=""
FoundErr=false
EnableUpload=false
id=request("id")
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
BODY{
BACKGROUND-COLOR: #E1F4EE;
font-size:9pt
}
.tx1 { height: 20px;font-size: 9pt; border: 1px solid; border-color: #000000; color: #0000FF}
-->
</style>
</head>
<body leftmargin="2" topmargin="5" marginwidth="0" marginheight="0" >
<%
if EnableUploadFile="No" then
response.write "系统未开放文件上传功能"
else
if session("china_uid")="" and session("china_cityadmin") and session("china_admin")="" then
response.Write("请登录后再使用本功能!")
else
select case upload_type
case 0
call upload_0() '使用化境无组件上传类
case else
'response.write "本系统未开放插件功能"
'response.end
end select
end if
end if
%>
</body>
</html>
<%
sub upload_0() '使用化境无组件上传类
set upload=new upfile_class ''建立上传对象
upload.GetData(104857600) '取得上传数据,限制最大上传100M
if upload.err > 0 then '如果出错
select case upload.err
case 1
response.write "请先选择你要上传的文件!"
case 2
response.write "你上传的文件总大小超出了最大限制(100M)"
end select
response.end
end if
PhotoUrlID=Clng(trim(upload.form("PhotoUrlID")))
if PhotoUrlID>0 then
SavePath = SaveUpFilesPath '存放上传文件的目录
else
SavePath = SaveUpFilesPath '存放上传文件的目录
end if
if right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)
set rs=Server.CreateObject("adodb.recordset")
rs.Open "select * from upfile",conn,1,3
for each formName in upload.file '列出所有上传了的文件
set ofile=upload.file(formName) '生成一个文件对象
oFileSize=ofile.filesize
if oFileSize<100 then
msg="请先选择你要上传的文件!"
FoundErr=True
else
select case PhotoUrlID
case 0
if oFileSize>(MaxFileSize*1024) then
msg="文件大小超过了限制,最大只能上传" & CStr(MaxFileSize) & "K的文件!"
FoundErr=true
end if
case 1
if oFileSize>(10000*1024) then
msg="文件大小超过了限制,最大只能上传10M的文件!"
FoundErr=true
end if
end select
end if
fileExt=lcase(ofile.FileExt)
arrUpFileType=split(UpFileType,"|")
for i=0 to ubound(arrUpFileType)
if fileEXT=trim(arrUpFileType(i)) then
EnableUpload=true
exit for
end if
next
if fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" then
EnableUpload=false
end if
if EnableUpload=false then
msg="这种文件类型不允许上传!\n\n只允许上传这几种文件类型:" & UpFileType
FoundErr=true
end if
strJS="<SCRIPT language=javascript>" & vbcrlf
if FoundErr<>true then
randomize
ranNum=int(900*rnd)+100
picname=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
filename=SavePath&picname
ofile.SaveToFile Server.mappath(FileName) '保存文件
rs.AddNew
rs("filename")=picname
rs("username")=session("china_uid")
rs.Update
response.write "文件上传成功!文件大小为:" & cstr(round(oFileSize/1024)) & "K"
select case PhotoUrlID
case 0
strJS=strJS & "parent.document.postart.dpic.value='" & picname & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize1.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 1
strJS=strJS & "parent.document.myform.DownloadUrl.value='" & fileName & "';" & vbcrlf
strJS=strJS & "parent.document.myform.FileSize.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 2
response.redirect "admin/link_img.asp?id="&id&"&web="&picname
'strJS=strJS & "parent.document.myform.PhotoUrl2.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize2.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 3
strJS=strJS & "parent.document.myform.CompVisualize.value='" & fileName & "';" & vbcrlf
' strJS=strJS & "parent.document.myform.PhotoSize3.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 4
strJS=strJS & "parent.document.myform.PhotoUrl4.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize4.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 5
strJS=strJS & "parent.document.myform.CompHonor.value='" & fileName & "';" & vbcrlf
' strJS=strJS & "parent.document.myform.PhotoSize5.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 6
strJS=strJS & "parent.document.myform.DefaultPicUrl.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize6.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 7
strJS=strJS & "parent.document.myform.MovieAddr.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize6.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
end select
else
strJS=strJS & "alert('" & msg & "');" & vbcrlf
strJS=strJS & "history.go(-1);" & vbcrlf
end if
strJS=strJS & "</script>" & vbcrlf
response.write strJS
if PhotoUrlID=1 then
response.redirect "admin/ad.asp?id="&id&"&picname="&picname
end if
set file=nothing
next
rs.close
set rs=nothing
set upload=nothing
end sub
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
本来是看到500分才来的,发现是假,那么就不准备回答你了..
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询