ASP realizes voice upload

Source: Internet
Author: User
Tags chr strlen

<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>

Table sound Field ID numeric 9 (self-increasing) WAV image Wavinfo varchar wavsize

Save.asp ' writes sound files to the database

<%@ 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 (+) & 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 (' voice upload succeeded, please return! '); 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 (+) & 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
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.