asp中我复制了一个图片上传的代码,并修改了但是图片地址出不来!
下面是Upload_Photo2.asp的代码。(原来的代码中没有数字2,我改的都在后面加个数字2.)<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
BODY{
BACKGROUND-COLOR: #ffffff;
font-size:9pt
}
.tx1 { height: 20px;font-size: 9pt; border: 1px solid; border-color: #000000; color: #0000FF}
-->
</style>
<SCRIPT language=javascript>
function check()
{
var strFileName=document.form2.FileName.value;
if (strFileName=="")
{
alert("请选择要上传的文件");
document.form2.FileName.focus();
return false;
}
}
</SCRIPT>
</head>
<body leftmargin="0" topmargin="0">
<form action="Upfile_Photo2.asp" method="post" name="form2" onSubmit="return check()" enctype="multipart/form-data">
<input name="FileName" type="FILE" class="tx1" size="30">
<input type="submit" name="Submit" value="上传" style="border:1px double rgb(88,88,88);font:9pt">
<input name="PhotoUrlID2" type="hidden" id="PhotoUrlID2" value="<%=Clng(trim(request("PhotoUrlID2")))%>">
</form>
</body>
</html>
下面是Upfile_Photo2.asp的代码。
<%@language=vbscript codepage=936 %>
<!--#include file="Inc/config.asp"-->
<!--#include file="Inc/upfile_class.asp"-->
<%
const upload2_type=0 '上传方法:0=无惧无组件上传类,1=FSO上传 2=lyfupload,3=aspupload,4=chinaaspupload
dim upload2,oFile,formName,SavePath,filename,fileExt,oFileSize
dim EnableUpload
dim arrUpFileType
dim ranNum
dim msg,FoundErr
dim PhotoUrlID2
msg=""
FoundErr=false
EnableUpload=false
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
BODY{
BACKGROUND-COLOR: #FFFFFF;
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("AdminName")="" then
response.Write("请登录后再使用本功能!")
else
select case upload2_type
case 0
call upload2_0() '使用化境无组件上传类
case else
'response.write "本系统未开放插件功能"
'response.end
end select
end if
end if
%>
</body>
</html>
<%
sub upload2_0() '使用化境无组件上传类
set upload2=new upfile_class ''建立上传对象
upload2.GetData(104857600) '取得上传数据,限制最大上传100M
if upload2.err > 0 then '如果出错
select case upload2.err
case 1
response.write "请先选择你要上传的文件!"
case 2
response.write "你上传的文件总大小超出了最大限制(100M)"
end select
response.end
end if
PhotoUrlID2=Clng(trim(upload2.form("PhotoUrlID2")))
if PhotoUrlID2>0 then
SavePath = SaveUpFilesPath '存放上传文件的目录
else
SavePath = SaveUpFilesPath '存放上传文件的目录
end if
if right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)
for each formName in upload2.file '列出所有上传了的文件
set ofile=upload2.file(formName) '生成一个文件对象
oFileSize=ofile.filesize
if oFileSize<100 then
msg="请先选择你要上传的文件!"
FoundErr=True
else
select case PhotoUrlID2
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
filename=SavePath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
ofile.SaveToFile Server.mappath(FileName) '保存文件
response.write "文件上传成功!文件大小为:" & cstr(round(oFileSize/1024)) & "K"
select case PhotoUrlID2
case 0
strJS=strJS & "parent.document.myform.PhotoUrl.value='" & fileName & "';" & 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
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.'" & 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.'" & 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 11
strJS=strJS & "parent.document.myform.pic1.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize6.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 12
strJS=strJS & "parent.document.myform.pic2.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize6.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 13
strJS=strJS & "parent.document.myform.pic3.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize6.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 14
strJS=strJS & "parent.document.myform.pic4.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize6.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 15
strJS=strJS & "parent.document.myform.pic5.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
set file=nothing
next
set upload2=nothing
end sub
%>
还需要哪个文件 希望大家再说出来, 不太懂 刚搞。这个网站源码本来只有两个图片上传,但是帮朋友想搞个小站,有三个图片页面,需要三个图片上传功能。希望各位高人指点迷津,现在的情况是,图片浏览的路径是正确的,也能上传成功,但是图片名称那里却没有图片的地址。我点确定总提示我错误,说图片名称不能为空。不知道那里有问题。