求一个能上传小说和图片的网站源码
1个回答
展开全部
这是我用的asp的,图片存在UpImages文件下,图片文件存在数库里,别外你自添加数据连接吧;
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>写日记</title>
<% if session("user")="" then
response.write"非法操作"
response.end
end if
%>
<link href="Css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
td { font-size: 12px; line-height: 18px; border-style: none; color: #333333}
body {
background-image: url(image/94d48012f93a637cf819b897.jpg);
}
.STYLE10 {font-size: 10px; font-family: "宋体"; }
.STYLE12 {font-size: 12px; font-family: "楷体_GB2312"; }
-->
</style></head>
<!--#include file="Conn.asp"-->
<body>
<table width="800" border="0" align="center" cellspacing="0">
<tr>
<th align="right" scope="col"> <span class="STYLE12">
<script language="JavaScript" type="text/javascript">
var pp,mm,month;
mydate=new Date();
pp=mydate.getDay();
month=mydate.getMonth()+1;
switch(pp)
{case 0: mm="星期日";break;
case 1: mm="星期一";break;
case 2:mm="星期二";break;
case 3: mm="星期三";break;
case 4: mm="星期四" ;break;
case 5 : mm="星期五";break;
case 6 : mm="星期六";break;
}
document.write("今天是:"+mydate.getYear()+"年"+month+"月"+mydate.getDate()
+"日"+" "+mm+" ");
</script>
</span></th>
</tr>
<tr>
<th height="40" scope="col"><img src="image/top.gif" width="800" height="157" alt="书丛制作" /></th>
</tr>
<tr>
<td height="25" align="center" background="image/ph.gif">写文章</td>
</tr>
</table>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#CCFFFF"><form action="write.asp?action=Addnew" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="138" align="right">文章标题:</td>
<td colspan="2"><label>
<input name="title" type="text" id="title" />
</label></td>
</tr>
<tr>
<td align="right"> </td>
<td width="236"><label></label>
<label for="file"></label>
<input type="file" name="file" id="file" /></td>
<td width="426"> 心情状态:
<select name="select">
<option value="一般" selected="selected">一般</option>
<option value="非常愉快">非常愉快</option>
<option value="愉快">愉快</option>
<option value="不好">不好</option>
<option value="失落">失落</option>
</select></td>
</tr>
<tr>
<td align="right">文章内容:</td>
<td colspan="2"><label>
<textarea name="content" cols="80" rows="20" id="content"></textarea>
</label></td>
</tr>
<tr>
<td align="right">操作:</td>
<td colspan="2"><label>
<input type="submit" name="Submit" value="提交" />
</label></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<table width="800" border="0" align="center" cellspacing="0">
<tr>
<th height="3" scope="col"><hr size="1" /></th>
</tr>
</table>
<table width="800" border="0" align="center" cellspacing="0">
<tr>
<th align="center" scope="col"><span class="STYLE10">Copyright 2009 ? www.pttjj.com.cn All Rights Reserved.<br />
版权所有: | 技术支持:<a href="mailto:yaoyaovip@yahoo.com.cn">书丛</a> | 渝ICP备000**0号 </span></th>
</tr>
</table>
<%
if request("action") = "Addnew" then
newline = chrB(13) & chrB(10) 'newline表示二进制的回车符
filesize = Request.TotalBytes 'filesize是表单数据大小
filedata = Request.BinaryRead(filesize) 'filedata是表单的二进制数据
divider = leftB(filedata,clng(instrb(filedata,newline))-1) 'divider是分割符
Set Rs = Server.CreateObject("ADODB.RecordSet")
Sql="Select * From word"
Rs.Open Sql,conn,3,3
Rs.addnew
k = 1
While instrb(k,filedata,divider) < instrb((instrb(k,filedata,divider)+lenb(divider)),filedata,divider)
start = instrb(k,filedata,divider) + lenb(divider) +2
endsize = instrb((instrb(k,filedata,divider) + lenb(divider)),filedata,divider) - start - 2
content = midb(filedata,start,endsize) '取文件说明部分
start_name = instrb(content,toByte("name="""))
end_name = instrb(start_name + 6,content,toByte(""""))
nametag = midb(content,start_name+6,end_name-start_name-6) '取文件说明部分中name=""中的内容,即表单元素的名称
pos1_filename = instrb(end_name,content,toByte("filename="""))
'如果是文件框,则文件说明部分应有filename="",那么pos1_filename不等于0
If pos1_filename = 0 Then '表单中不属于文件上传的数据处理
namevalue = toStr(midb(content,end_name+5,lenb(content)-end_name-4)) '取文件内容
' 将文件说明部分的name=""中的内容与表单元素的名称进行比较,把相应的内容加入数据库
If(InStr(toStr(nametag),"file") > 0)Then 'CenterID2'为表单控件的name属性值,以下同
Rs("image") = namevalue
session("CenterID") = namevalue '用于上传文件保存时的文件名中
End If
If(InStr(toStr(nametag),"title") > 0)Then
Rs("title") = namevalue
if namevalue="" then
Response.Write "<Script>alert('请输入标题!')</Script>"
response.end
end if
End If
If(InStr(toStr(nametag),"content") > 0)Then
Rs("content") = namevalue
if namevalue="" then
Response.Write "<Script>alert('请输入内容!')</Script>"
response.end
end if
End If
If(InStr(toStr(nametag),"select") > 0)Then
Set Rs1 = Server.CreateObject("ADODB.RecordSet")
Sql="Select * From mun"
Rs1.Open Sql,conn,3,3
Rs1("mun")=namevalue
Rs1.update
Rs1.Close
Set Rs1=nothing
End If
Rs("wtime") = year(now)&"-"&month(now)&"-"&day(now)
'Response.Write (namevalue)
'Response.Write(" <br>")
else '处理文件上传部分的数据
pos2_filename = instrb(pos1_filename+10,content,toByte(""""))
fullpath = midb(content,pos1_filename+10,pos2_filename-pos1_filename-10) '从文件说明部分中取出文件路径
covername=GetFileName(toStr(fullpath))
If(fullpath <> "")Then '如果有上传的文件,执行以下代码
dim bStart ' 取二进制流文件部分开始位置
bStart = instrb(start,filedata,newline&newline)+3
dim bEnd ' 取二进制流文件部分结束位置
bEnd=inStrB(bStart+6,filedata,divider)-bStart-3
dim stm ' 定义一个 adodb.stream 源对象 stm, 用以拷贝二进制流文件部分至另一 adodb.stream fromStm
set stm=createObject("adodb.stream")
stm.type=1 ' 二进制模式
stm.mode=3 ' 指定打开模式为读写
stm.open
stm.write filedata '写入二进制流内容
dim fromStm '定义 adodb.stream 对象 fromStm, 以保存文件
set fromStm=createOBject("adodb.stream")
with fromStm
.type=1
.mode=3
.open
stm.position = bStart ' 指定 stm 对象的起始位置, 以变量 bStart 的值为起始位置
stm.copyTo fromStm, bEnd ' 拷贝 stm 二进制流至 fromStm 对象, 长度为 bEnd 变量的长度
.saveTofile server.MapPath (covername),2' 保存文件, 如果存在相同名称, 则覆盖
.close
end with
set fromStm = nothing
stm.close
set stm = nothing
Rs("image") =covername '将文件的相对路径写入数据库中
end if
end if
k = instrb((instrb(k,filedata,divider)+lenb(divider)),filedata,divider)
Wend
Rs.update
Rs.close
set Rs = nothing
response.Redirect"mylife.asp"
end if
function toStr(Byt) '将二进制转换为字符串
toStr=""
for i=1 to lenb(byt)
blow = midb(byt,i,1)
if ascb(blow)>127 then
toStr = toStr&chr(ascw(midb(byt,i+1,1)&blow)) '
i = i+1
else
toStr = toStr&chr(ascb(blow))
end if
Next
End function
Function toByte(Str) '将字符串转换为二进制
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode <0 Then iCode = iCode + 65535
If iCode>255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function
Function GetFileName(imagespath)'将路径转换为时间,并使上传的文件不重名
If imagespath <> "" Then
rname=right(toStr(fullpath),len(toStr(fullpath))-InStrRev(toStr(fullpath),".")+1)'获得后缀名
GetFileName = "UpImages/" & year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&rname
Else
GetFileName =""
End If
End Function
%>
</body>
</html>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>写日记</title>
<% if session("user")="" then
response.write"非法操作"
response.end
end if
%>
<link href="Css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
td { font-size: 12px; line-height: 18px; border-style: none; color: #333333}
body {
background-image: url(image/94d48012f93a637cf819b897.jpg);
}
.STYLE10 {font-size: 10px; font-family: "宋体"; }
.STYLE12 {font-size: 12px; font-family: "楷体_GB2312"; }
-->
</style></head>
<!--#include file="Conn.asp"-->
<body>
<table width="800" border="0" align="center" cellspacing="0">
<tr>
<th align="right" scope="col"> <span class="STYLE12">
<script language="JavaScript" type="text/javascript">
var pp,mm,month;
mydate=new Date();
pp=mydate.getDay();
month=mydate.getMonth()+1;
switch(pp)
{case 0: mm="星期日";break;
case 1: mm="星期一";break;
case 2:mm="星期二";break;
case 3: mm="星期三";break;
case 4: mm="星期四" ;break;
case 5 : mm="星期五";break;
case 6 : mm="星期六";break;
}
document.write("今天是:"+mydate.getYear()+"年"+month+"月"+mydate.getDate()
+"日"+" "+mm+" ");
</script>
</span></th>
</tr>
<tr>
<th height="40" scope="col"><img src="image/top.gif" width="800" height="157" alt="书丛制作" /></th>
</tr>
<tr>
<td height="25" align="center" background="image/ph.gif">写文章</td>
</tr>
</table>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#CCFFFF"><form action="write.asp?action=Addnew" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="138" align="right">文章标题:</td>
<td colspan="2"><label>
<input name="title" type="text" id="title" />
</label></td>
</tr>
<tr>
<td align="right"> </td>
<td width="236"><label></label>
<label for="file"></label>
<input type="file" name="file" id="file" /></td>
<td width="426"> 心情状态:
<select name="select">
<option value="一般" selected="selected">一般</option>
<option value="非常愉快">非常愉快</option>
<option value="愉快">愉快</option>
<option value="不好">不好</option>
<option value="失落">失落</option>
</select></td>
</tr>
<tr>
<td align="right">文章内容:</td>
<td colspan="2"><label>
<textarea name="content" cols="80" rows="20" id="content"></textarea>
</label></td>
</tr>
<tr>
<td align="right">操作:</td>
<td colspan="2"><label>
<input type="submit" name="Submit" value="提交" />
</label></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<table width="800" border="0" align="center" cellspacing="0">
<tr>
<th height="3" scope="col"><hr size="1" /></th>
</tr>
</table>
<table width="800" border="0" align="center" cellspacing="0">
<tr>
<th align="center" scope="col"><span class="STYLE10">Copyright 2009 ? www.pttjj.com.cn All Rights Reserved.<br />
版权所有: | 技术支持:<a href="mailto:yaoyaovip@yahoo.com.cn">书丛</a> | 渝ICP备000**0号 </span></th>
</tr>
</table>
<%
if request("action") = "Addnew" then
newline = chrB(13) & chrB(10) 'newline表示二进制的回车符
filesize = Request.TotalBytes 'filesize是表单数据大小
filedata = Request.BinaryRead(filesize) 'filedata是表单的二进制数据
divider = leftB(filedata,clng(instrb(filedata,newline))-1) 'divider是分割符
Set Rs = Server.CreateObject("ADODB.RecordSet")
Sql="Select * From word"
Rs.Open Sql,conn,3,3
Rs.addnew
k = 1
While instrb(k,filedata,divider) < instrb((instrb(k,filedata,divider)+lenb(divider)),filedata,divider)
start = instrb(k,filedata,divider) + lenb(divider) +2
endsize = instrb((instrb(k,filedata,divider) + lenb(divider)),filedata,divider) - start - 2
content = midb(filedata,start,endsize) '取文件说明部分
start_name = instrb(content,toByte("name="""))
end_name = instrb(start_name + 6,content,toByte(""""))
nametag = midb(content,start_name+6,end_name-start_name-6) '取文件说明部分中name=""中的内容,即表单元素的名称
pos1_filename = instrb(end_name,content,toByte("filename="""))
'如果是文件框,则文件说明部分应有filename="",那么pos1_filename不等于0
If pos1_filename = 0 Then '表单中不属于文件上传的数据处理
namevalue = toStr(midb(content,end_name+5,lenb(content)-end_name-4)) '取文件内容
' 将文件说明部分的name=""中的内容与表单元素的名称进行比较,把相应的内容加入数据库
If(InStr(toStr(nametag),"file") > 0)Then 'CenterID2'为表单控件的name属性值,以下同
Rs("image") = namevalue
session("CenterID") = namevalue '用于上传文件保存时的文件名中
End If
If(InStr(toStr(nametag),"title") > 0)Then
Rs("title") = namevalue
if namevalue="" then
Response.Write "<Script>alert('请输入标题!')</Script>"
response.end
end if
End If
If(InStr(toStr(nametag),"content") > 0)Then
Rs("content") = namevalue
if namevalue="" then
Response.Write "<Script>alert('请输入内容!')</Script>"
response.end
end if
End If
If(InStr(toStr(nametag),"select") > 0)Then
Set Rs1 = Server.CreateObject("ADODB.RecordSet")
Sql="Select * From mun"
Rs1.Open Sql,conn,3,3
Rs1("mun")=namevalue
Rs1.update
Rs1.Close
Set Rs1=nothing
End If
Rs("wtime") = year(now)&"-"&month(now)&"-"&day(now)
'Response.Write (namevalue)
'Response.Write(" <br>")
else '处理文件上传部分的数据
pos2_filename = instrb(pos1_filename+10,content,toByte(""""))
fullpath = midb(content,pos1_filename+10,pos2_filename-pos1_filename-10) '从文件说明部分中取出文件路径
covername=GetFileName(toStr(fullpath))
If(fullpath <> "")Then '如果有上传的文件,执行以下代码
dim bStart ' 取二进制流文件部分开始位置
bStart = instrb(start,filedata,newline&newline)+3
dim bEnd ' 取二进制流文件部分结束位置
bEnd=inStrB(bStart+6,filedata,divider)-bStart-3
dim stm ' 定义一个 adodb.stream 源对象 stm, 用以拷贝二进制流文件部分至另一 adodb.stream fromStm
set stm=createObject("adodb.stream")
stm.type=1 ' 二进制模式
stm.mode=3 ' 指定打开模式为读写
stm.open
stm.write filedata '写入二进制流内容
dim fromStm '定义 adodb.stream 对象 fromStm, 以保存文件
set fromStm=createOBject("adodb.stream")
with fromStm
.type=1
.mode=3
.open
stm.position = bStart ' 指定 stm 对象的起始位置, 以变量 bStart 的值为起始位置
stm.copyTo fromStm, bEnd ' 拷贝 stm 二进制流至 fromStm 对象, 长度为 bEnd 变量的长度
.saveTofile server.MapPath (covername),2' 保存文件, 如果存在相同名称, 则覆盖
.close
end with
set fromStm = nothing
stm.close
set stm = nothing
Rs("image") =covername '将文件的相对路径写入数据库中
end if
end if
k = instrb((instrb(k,filedata,divider)+lenb(divider)),filedata,divider)
Wend
Rs.update
Rs.close
set Rs = nothing
response.Redirect"mylife.asp"
end if
function toStr(Byt) '将二进制转换为字符串
toStr=""
for i=1 to lenb(byt)
blow = midb(byt,i,1)
if ascb(blow)>127 then
toStr = toStr&chr(ascw(midb(byt,i+1,1)&blow)) '
i = i+1
else
toStr = toStr&chr(ascb(blow))
end if
Next
End function
Function toByte(Str) '将字符串转换为二进制
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode <0 Then iCode = iCode + 65535
If iCode>255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function
Function GetFileName(imagespath)'将路径转换为时间,并使上传的文件不重名
If imagespath <> "" Then
rname=right(toStr(fullpath),len(toStr(fullpath))-InStrRev(toStr(fullpath),".")+1)'获得后缀名
GetFileName = "UpImages/" & year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&rname
Else
GetFileName =""
End If
End Function
%>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询