ASP realizes voice upload

Source: Internet
Author: User
Tags chr strlen
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
%>
Wav.asp ' Read data

<%@ 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 ("The network is busy now, the database connection has been wrong, please wait a few minutes to visit again.") ")
</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.ContentType = "Audio/x-wav"
Response.BinaryWrite RS ("wav"). GetChunk (7500000)
' Rs.close
' Set rs=nothing
Conn.close
Set conn=nothing
%>

Play.asp ' Try to listen

The!--<embed src= "wav.asp?id=6%>" autostart= "true" loop= "true" height= "the" width= "the" Volume= "" The "" The "" The "" "><br>-- >
!--set Showcontrols, Showdisplay, ShowStatusBar value is set to 0, will not display the corresponding things in the video window-->
<object id= "Nsplay" width=300 height=145 classid= "Clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase= activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701 "standby=" loads Microsoft Windows Media Player component ... "type=" Application/x-oleobject ">
<param name= "FileName" value= "wav.asp?id=<%=request (" id ")%>" >
<param name= "Showcontrols" value= "1" >
<param name= "Showdisplay" value= "1" >
<param name= "ShowStatusBar" value= "1" >
<param name= "AutoSize" value= "1" >
<embed src= "wav.asp?uid=<%=request (" id ")%>" width= "" height= "and" type= "Application/x-mplayer2" "pluginspage=" http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/"Filename=" husteradio.asx "Name=" Nsplay "showcontrols=" 1 "showdisplay=" 1 "showstatusbar=" 0 ">
</object>


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.