当前位置: 首页 > 图文教程 > 网络编程 > ASP > asp实现语音上传

ASP
ASP实例代码:搞个长文章分页代码
说说对象的复制
多个函数验证同一表单
查询某个字段没有值的所有记录的SQL语句怎么写?
ASP实例:一个简单的ASP无组件上传类
ASP实例讲解:用分页符实现长文章分页显示
ASP实例:动态网页中常用的6个ASP程序
ASP实例:词语搭配游戏的制作
ASP实例学习:随机生成文件名的函数
asp实例:测试WEB服务器
ASP实例:计数器程序详解
预防ASP网站被黑 彻底了解ASP木马
分享:XML HTTP Request的属性和方法简介
ASP架设:给每个IIS站点建立一个用户
ASP技巧:判断远程图片是否存在
故障解决:解决ASP脚本运行超时的方法
再说ASP输出N行N列表格
怎么判断一个对象是否已被释放
ASP实现网页打开任何类型文件都保存的方法
ASP技巧:利用函数InstrRev()获取当前文件名

ASP 中的 asp实现语音上传


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 73 ::
收藏到网摘: n/a

<script language="javascript">

function openScript(url, width, height){
var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=yes' );
}
</script>

<form action="save.asp" method="POST" enctype="multipart/form-data">
<tr>
<td width="17%" height="66">选择语音</td>
<td height="66" colspan="5">
<input type="file" name="wav" class="lan">
<input type="submit" name="Submit4" value="确定上传" class="lan"> <input name="button" type="button" class="bu" value="有声档案" onClick="openScript('../play.asp?id=<%=session("id")%>','','scrollbars=no,resizable=no,width=340,height=200')"></td>
</tr>
</form>
表 sound 字段 id numeric 9 (自增) wav image 16 wavinfo varchar 50 wavsize numeric
save.asp '将声音文件写入数据库

<%@ Language=VBScript %>
<!--#include file="../conn.asp"-->
<%
Response.expires=0
Server.ScriptTimeout =3600

call main()

sub main()


FormSize = Request.TotalBytes
FormData = Request.BinaryRead( FormSize )

bncrlf=chrb(13) & chrb(10)
divider=leftb(FormData,instrb(FormData,bncrlf)-1)
datastart=instrb(FormData,bncrlf & bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart

Wav = WavUp(FormSize,Formdata)

strTXT=mid(formdata,instr(formdata,Wav)+len(Wav)+1)
strTXT=bin2str(strTXT)

'wavinfo=findVar("wavinfo",strTXT)

set RS=server.createobject("ADODB.recordset")
SQL="select wav,wavsize,wavinfo from sound"
RS.Open SQL,conn,1,3

RS.Addnew
RS("wavinfo")=wavinfo
RS("wavsize")=dataend-2
if Len(Wav)>1 then
RS("wav").Appendchunk Wav
end if
RS.Update
RS.Close
set RS=nothing
conn.close
set conn=nothing
'response.Write(Request.ServerVariables ("REMOTE_ADDR"))
response.Write("<script language='javascript'>alert('语音上传成功了,请返回!');window.location.reload('sound.asp');</script>")
response.end
end sub

Function bin2str(binstr)
Dim varlen,clow,ccc,skipflag
skipflag=0
ccc = ""
varlen=LenB(binstr)
For i=1 To varlen
If skipflag=0 Then
clow = MidB(binstr,i,1)
If AscB(clow) > 127 Then
ccc =ccc & Chr(AscW(MidB(binstr,i+1,1) & clow))
skipflag=1
Else
ccc = ccc & Chr(AscB(clow))
End If
Else
skipflag=0
End If
Next
bin2str = ccc
End Function


Function WavUp(formsize,formdata)
bncrlf=chrb(13) & chrb(10)
divider=leftb(formdata,instrb(formdata,bncrlf)-1)
datastart=instrb(formdata,bncrlf & bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
WavUp=midb(formdata,datastart,dataend)
End Function


Function findVar(varName,strTxt)
startPos=1
strLen=len(varName)+2
for i=1 to len(strTXT)
varStart=instr(startPos,strTXT,varName)+strLen+3
varEnd=instr(varStart,strTXT,"--")-2
varValLen=varEnd-varStart

inVar=mid(strTXT,varStart,varValLen)
findVar=findVar & inVar

startPos=instr(varStart,strTXT,varName)
if startPos=0 then exit for
findVar=findVar & ","
next
End function
%>
wav.asp '读取数据

<%@ Language=VBScript %>
<% session.timeout=25%>
<%
set conn=server.CreateObject("adodb.connection")

connstr="Provider=sqloledb.1;Persist Security Info=False;User ID=sa;Initial Catalog=database;Data source=127.0.0.1;pwd="
conn.open connstr

if err.number<>0 or err then
err.clear
response.write Err.Description
response.end
%>
<script language="javascript">
alert("网络现在繁忙,数据库连接发生错误,请等待几分钟再访问。")
</script>
<%end if%>

<%
dim RS,id
set RS=Server.CreateObject("ADODB.Recordset")
SQL="select wav from sound where id='"&request("id")&"'"
RS.open SQL,conn,1,1
Response.Conte