⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file_upload.asp

📁 一个不错的企业网站源代码!
💻 ASP
字号:
<%@ Language=VBScript %>
<%
Response.Buffer=true
Response.Expires=0
%>
<!--#include file="upload.inc"-->
<!-- #include file="../dsn.asp" -->
<%
keyno=Request.QueryString("keyno")
tablename=Request.QueryString("tablename")
ptablename=trim(Request.QueryString("ptablename"))
if tablename="danwei" or tablename="cdanwei" or tablename="danweipic" then
		pictabname="danweipic"
		url="../upfile/"
		durl="./upfile/"
	else
		pictabname="edanweipic"	
		url="../english/upfile/"
		durl="./english/upfile/"
end if		
pic=Request.QueryString("pic")
if keyno="" then
		Response.End 
	else
		keyno=cint(keyno)
end if
if pic=0 then
		pictxt=""
	else
		pictxt=cstr(pic)
end if
	
set cn=server.CreateObject("ADODB.Connection")
cn.Open mycnstr
set rs=server.createobject("ADODB.recordset") 
set rs2=server.createobject("ADODB.recordset") 
set fs=CreateObject("Scripting.FileSystemObject")
htmlname="keyno="&keyno&"&pic="&pic&"&tablename="&tablename&"&ptablename="&ptablename
method=Request.QueryString("method")
sqltext="select * from danweipic where id="&keyno 
rs.Open sqltext,cn,1,1
if not rs.eof then
		filenames=rs("picname"&pictxt)
		picflag=rs("picflag"&pictxt)
end if
rs.Close 
if method="del" then
		if fs.FileExists(server.MapPath(url&filenames)) then   '删除文件
			fs.DeleteFile(server.MapPath(url&filenames))
		end if
	sqltext="select * from "+pictabname+" where id="&keyno   '更改数据库表实状态
	rs.Open sqltext,cn,1,2
	if not rs.EOF then
			deltablename=trim(rs("tablename"))
			picname=trim(rs("picname"))
			rs("picname"&pictxt)=""
			rs("picflag"&pictxt)=0
			rs("tablename")=""
			pid=rs("pid")
	end if
	rs.Update 
	rs.Close 
	sqltext="select * from "+ptablename+" where id="&pid   '删除应用代码
	rs2.Open sqltext,cn,1,2
	if not rs2.EOF then
			rs2("body")=Replace(rs2("body"),"<table width=100% border=0 cellspacing=0 cellpadding=0 align=center><tr><td align=center><img src="&durl&picname&"></td></tr></table>","")
			rs2("body")=Replace(rs2("body"),"<img src="&durl&picname&" align=left>","")
			rs2("body")=Replace(rs2("body"),"<img src="&durl&picname&" align=right>","")
			
	end if
	rs2.Update 
	rs2.Close 
end if
sqltext="select * from "+pictabname+" where id="&keyno 
rs.Open sqltext,cn,1,1
if not rs.eof then
		filenames=rs("picname"&pictxt)
		picflag=rs("picflag"&pictxt)
end if
rs.Close 
if Request.ServerVariables("REQUEST_METHOD") = "POST" then

	set upload=new upload_5xSoft 
	set file=upload.file("filename")
	formsize=file.filesize
	
	'Response.Write formsize
	'Response.Write file.filename
	'Response.End
	
		
	formsize=request.totalbytes 
	bz="1"

	dim fileclass(6)
	fileclass(1)="asp"
	fileclass(2)="php"
	fileclass(3)="htm"
	fileclass(4)="html"
	fileclass(5)="jsp"
	fileclass(6)="js"
	'Response.Write formsize
	'Response.Write picsize
		fileext=lcase(right(file.filename,4))
		newname=firname&code&keyno&fileext
	sqltext="select * from "+pictabname+" where id="&keyno
	rs.Open sqltext,cn,1,2
	if not rs.EOF then
			rs("picflag"&pictxt)=1
			rs("picname"&pictxt)=tablename&pictxt&newname
			rs("tablename")=ptablename
	end if
	rs.Update 
	rs.Close 
		file.SaveAs Server.mappath(url&tablename&pictxt&newname)  '文件保存	
		set self=Request.ServerVariables("script_name")'成功上传的检验
		if oldname<>"" then
			if fs.FileExists(server.MapPath(oldname)) then
				fs.DeleteFile(server.MapPath(oldname))
			end if
		end if	
		if fs.FileExists(server.MapPath(url&tablename&pictxt&newname)) then
		end if
		set rs=nothing 
		set cn=nothing 
		Response.Write("<script language=Javascript>")	
		Response.Write("window.opener.top.main.location.reload();")
		Response.Write("window.close()")
		Response.Write("</script>")
end if
%>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body {font-size: 12px; color: #000000; font-family: 宋体}
td {font-size: 12px; color: #000000; font-family: 宋体;line-height:130%}
.t1 {font:12px 宋体;color=000000} 
.t2 {font:12px 宋体;color:ffffff} 
-->
</style>
</head>
<title>文件上传</title>
<body bgcolor="#FF6633" leftmargin="1" topmargin="0" marginwidth="0" marginheight="0">
<form name="form2" enctype="multipart/form-data" action="file_upload.asp?<%=htmlname%>" method="post" onsubmit="return checkform()"> 
      <table width="100%" border="0" height="100%" bgcolor="#FF6633" cellpadding="2" cellspacing="1">
        <tr bgcolor="#FF6633"> 
          <td height="2">&nbsp;</td>
        </tr>
        <tr bgcolor="#FFFFFF" align="center"> 
          <td height="290">
			<%
			if sysmess<>"" then
				Response.Write("<font color=red>提示:"+sysmess+"</font><br>")
			end if
			%>
			
  			<table>
       			<tr align=center><td>
       			<%if picflag=1 then%>
       					<img src="<%=url%><%=filenames%>">
       				<%else%>
       					暂无图片
       			<%end if%>
       			</td></tr>
       			
   			</table>
          </td>
        </tr>
        <tr bgcolor="#FFFFFF"> 
          <td> 
            <table width="100%" border="0">
              <tr align="center"> 
                <td>
                    上传图片&nbsp;<input type="file" name="filename">
                </td>
              </tr>
              <tr align="center"> 
                <td height="5"></td>
              </tr>
              <tr align="center"> 
                 <td>
                 <%if picflag=1 then%>
					<input type="button" name="delete" value="删除图片" onclick="Javascript:delpic()">
                 <%end if%>
                    <input type="submit" name="Submit" value="上传文件">&nbsp;&nbsp;&nbsp;&nbsp;               
                    <input type="button" name="cancel" value="关闭窗口" onclick="Javascript:window.opener.top.main.location.reload();window.close()"></form>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
</form>
</body>
</html>
<script language=Javascript>
	function checkform(form1)
	{
		var filename
		filename=document.form2.filename.value;
		if (filename=="") 
			{ return false}
		return true
	}
	
	function delpic()
	{
		if (confirm('您确认要删除该文件吗?')==true)
		{
		window.location.href="file_upload.asp?method=del&<%=htmlname%>"
		return false;
		}
	}
</script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -