Asp enables voice Upload
<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"> select voice </td>
<Td height = "66" colspan = "5">
<Input type = "file" name = "wav" class = "lan">
<Input type = "submit" name = "Submit4" value = "confirm Upload" class = "lan"> <input name = "button" type = "button" class = "bu "value =" audio file "onClick =" openScript ('.. /play. asp? Id = <% = session ("id") %> ', '', 'scrollbars = no, resizable = no, width = 340, height = 200 ') "> </td>
</Tr>
</Form>
Table sound field id numeric 9 (auto-increment) wav image 16 wavinfo varchar 50 wavsize numeric
Save. asp write audio 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 (13) & chrb (10)
Divider = leftb (FormData, role B (FormData, bncrlf)-1)
Datastart = instrb (FormData, bncrlf & bncrlf) + 4
Dataend = Consumer B (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 uploaded successfully. 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 (13) & chrb (10)
Divider = leftb (formdata, role B (formdata, bncrlf)-1)
Datastart = instrb (formdata, bncrlf & bncrlf) + 4
Dataend = Consumer B (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
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, and the database connection error occurs. Please wait for a few minutes and try 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 'test
<! -- <Embed src = "wav. asp? ID = 6%> "AUTOSTART =" true "LOOP =" TRUE "HEIGHT =" 45 "WIDTH =" 320 "VOLUME =" 100 "> <br> -->
<! -- Set ShowControls, ShowDisplay, and ShowStatusBar to 0, and the corresponding things in the video window will not be displayed -->
<Object id = "NSPlay" WIDTH = 300 HEIGHT = 145 classid = "CLSID: 22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase = "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby = "load Microsoft Windows Media Player components... "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 =" 320 "height =" 125 "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>