www.gusucode.com > 木犁IT产品管理系统 1.0 beta1码程序 > manage/Up2.asp

    <!--#include file="Up3.inc"-->
<%fd=request("fd")%>
<html>
<head>
<title>上传产品图片</title>
<script language="JavaScript"> 
<!-- 
var flag=false; 
function DrawImage(ImgD){ 
 var image=new Image(); 
 image.src=ImgD.src; 
 if(image.width>0 && image.height>0){ 
  flag=true; 
  if(image.width/image.height>= 100/100){ 
   if(image.width>100){
    ImgD.width=100; 
    ImgD.height=(image.height*100)/image.width; 
   }else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } 
   ImgD.alt= "点击查看详细信息..."; 
  } 
  else{ 
   if(image.height>100){
    ImgD.height=100; 
    ImgD.width=(image.width*100)/image.height; 
   }else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } 
   ImgD.alt="点击查看详细信息..."; 
  } 
 }
}

function Addpic(imagePath){
	window.opener.AddPro.<%=fd%>.focus();								
	window.opener.document.AddPro.<%=fd%>.value=imagePath;
    window.opener=null;
    window.close();
}
//--> 
</script> 
<link href="text.css" rel="stylesheet" type="text/css">
</head>
<body >
<table width=400 border=0 align="center" cellpadding="6" cellspacing="1" bgcolor="#A2A2A2">
  <tr><td width=100% height=100% align="center" bgcolor="#F2F2F2" class=tablebody1 >
<%
dim upload,file,formName,formPath,filename,fileExt
dim ranNum
call UpFile()
'===========无组件上传(upload_0)====================
sub UpFile()
set upload=new UpFile_Class '建立上传对象
upload.GetData (1000*1024) '取得上传数据,此处即为150 K

if upload.err > 0 then
select case upload.err
case 1
Response.Write "请先选择你要上传的文件 [ <a href=# onclick=history.go(-1)>请重新上传</a> ]"
case 2
Response.Write "图片大小超过了限制 1024 K [ <a href=# onclick=history.go(-1)>请重新上传</a> ]"
end select
exit sub
else
formPath=upload.form("filepath") '文件保存目录,此目录必须为程序可读写
if formPath="" then
formPath="../UploadFiles"
end if
'在目录后加(/)
if right(formPath,1)<>"/" then 
formPath=formPath&"/"
end if 
for each formName in upload.file '列出所有上传了的文件
set file=upload.file(formName) '生成一个文件对象
if file.filesize<100 then
response.write "请先选择你要上传的图片! [ <a href=# onclick=history.go(-1)>请重新上传</a> ]"
response.end
end if

fileExt=lcase(file.FileExt)
if CheckFileExt(fileEXT)=false then
response.write "文件格式不正确! [ <a href=# onclick=history.go(-1)>请重新上传</a> ]"
response.end
end if

'randomize
ranNum=int(90000*rnd)+10000
filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
if file.FileSize>0 then '如果 FileSize > 0 说明有文件数据
result=file.SaveToFile(Server.mappath(filename)) '保存文件
if result="ok" then
response.write "文件:<font color='#ff0000'>"&File.FilePath&file.FileName&"</font>上传成功!<br>"
response.write"保存路径:<input type=""text"" style=""border-style: solid; border-width: 1"" value="""&filename&"""><br>[<a href=# onclick=""Addpic('"&filename&"')"">点击这里把图片路径添加到文本框中</a>]"

else
response.write File.FilePath&file.FileName&" 上传失败,"&result&"<br>"
end if
end if
set file=nothing
next
set upload=nothing
end if
end sub

'判断文件类型是否合格
Private Function CheckFileExt (fileEXT)
dim Forumupload
Forumupload="gif,jpg,bmp,jpeg,swf,png"
Forumupload=split(Forumupload,",")
for i=0 to ubound(Forumupload)
if lcase(fileEXT)=lcase(trim(Forumupload(i))) then
CheckFileExt=true
exit Function
else
CheckFileExt=false
end if
next
End Function
%>
</td>
  </tr></table>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="120" align="center"><%if lcase(FileExt)="swf" then%>
	<embed src="<%=filename%>" type="application/x-shockwave-flash" width="400" height="120" align="center">
	<%else%><img src=<%=filename%> border=0 width=100 height=100 onload=javascript:DrawImage(this);><%end if%></td>
</table>
</body>
</html>