高手帮忙。怎样让用户自己上传视频文件。。把客户端的上传到服务器端

lovednet 2005-07-13 11:36:58
高手帮忙。怎样让用户自己上传视频文件。。把客户端的上传到服务器端高手帮忙。
...全文
287 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 2005-07-13
  • 打赏
  • 举报
回复
'==================================================================--
'
' 用ASP实现无组件上传/下载文件
'
' 功能简介
' 将上传的文件数据保存到数据库中,可以处理表单中的多个上传文件的情况
' 适用于各种数据库,使用ADO的方法连接数据库
' 本示例中使用的是ACCESS数据库:zj.mdb
' 表:tb_img(id int(自增列),path text(255) 保存上传文件的目录
' ,fname text(250) 保存上传的文件名,img ole对象 保存上传的文件内容
' ,type text(250) 保存上传的文件类型
'
' 邹建 2003.10
'==================================================================


'==================================================================
'
' 上传文件的HTML页: zj_up.htm
'
'==================================================================
<html>
<head>
<title>文件上传保存到数据库中</title>
</head>
<body>
<form name="form1" enctype="multipart/form-data" method="post" action="zj_up.asp">
<p>
<input type="file" name="file">
<input type="submit" name="Submit" value="上传">
</p>
</form>
</body>
</html>


'==================================================================
'
' 上传文件保存到数据库的ASP页: zj_up.asp
'
'==================================================================
<%
Response.Expires=0
Function f_Bin2Str(ByVal sBin)
Dim iI, iLen, iChr, iRe
iRe = ""
If Not IsNull(sBin) Then
iLen = LenB(sBin)
For iI = 1 To iLen
iChr = MidB(sBin, iI, 1)
If AscB(iChr) > 127 Then
iRe = iRe & Chr(AscW(MidB(sBin, iI + 1, 1) & iChr))
iI = iI + 1
Else
iRe = iRe & Chr(AscB(iChr))
End If
Next
End If
f_Bin2Str = iRe
End Function
iConcStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False" & _
";Data Source=" & server.mappath("zj.mdb")
iSql="tb_img"
set iRe=Server.CreateObject("ADODB.Recordset")
iRe.Open iSql,iConcStr,1,3
iLen=Request.TotalBytes
sBin=Request.BinaryRead(iLen)
iCrlf1 = ChrB(13) & ChrB(10)
iCrlf2 = iCrlf1 & iCrlf1
iLen = InStrB(1, sBin, iCrlf1) - 1
iSpc = LeftB(sBin, iLen)
sBin = MidB(sBin, iLen + 34)
iPos1 = InStrB(sBin, iCrlf2) - 1
While iPos1 > 0
iStr = f_Bin2Str(LeftB(sBin, iPos1))
iPos1 = iPos1 + 5
iPos2 = InStrB(iPos1, sBin, iSpc)

iPos3 = InStr(iStr, "; filename=""") + 12
If iPos3 > 12 Then
iStr = Mid(iStr, iPos3)
iPos3 = InStr(iStr, Chr(13) & Chr(10) & "Content-Type: ") - 2
iFn = Left(iStr, iPos3)
If iFn <> "" Then
iRe.AddNew
ire("path")=left(iFn,instrrev(iFn,"\"))
iRe("fname") = mid(iFn,instrrev(iFn,"\")+1)
iRe("type") = Mid(iStr, iPos3 + 18)
iRe("img").AppendChunk MidB(sBin, iPos1, iPos2 - iPos1)
iRe.Update
End If
End If

sBin = MidB(sBin, iPos2 + iLen + 34)
iPos1 = InStrB(sBin, iCrlf2) - 1
Wend
iRe.close
set iRe=Nothing
%>

'==================================================================
'
' 下载数据的ASP页: zj_down.asp
'
'==================================================================
<%
Response.Buffer=true
Response.Clear

iConcStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False" & _
";Data Source=" & server.mappath("zj.mdb")
set iRe=server.createobject("adodb.recordset")
iSql="tb_img"
iRe.open iSql,iconcstr,1,1
Response.ContentType=ire("type")
Response.BinaryWrite iRe("img")

iRe.close
set iRe=Nothing
%>


a.html
_____________________________________________
<img src="show.asp?id=1">
zjcxc 2005-07-13
  • 打赏
  • 举报
回复
'VB/VBA中实现数据库中的文件存取

'示例数据库为ACCESS数据库,用SQL数据库的话,只需要改连接字符串
'
'*************************************************************************
'**
'** 使用 ADODB.Stream 保存/读取文件到数据库
'** 引用 Microsoft ActiveX Data Objects 2.5 Library 及以上版本
'**
'** ----- 数据库连接字符串模板 ---------------------------------------
'** ACCESS数据库
'** iConcStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False" & _
'** ";Data Source=数据库名"
'**
'** SQL数据库
'** iConcStr = "Provider=SQLOLEDB.1;Persist Security Info=True;" & _
'** "User ID=用户名;Password=密码;Initial Catalog=数据库名;Data Source=SQL服务器名"
'**
'*************************************************************************
'
'保存文件到数据库中
Sub s_SaveFile()
Dim iStm As ADODB.Stream
Dim iRe As ADODB.Recordset
Dim iConcStr As String

'ACCESS数据库的连接字符串
iConcStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False" & _
";Data Source=F:\My Documents\客户资料1.mdb"

'SQL数据库的连接字符串
iConcStr = "Provider=SQLOLEDB.1;Persist Security Info=True;" & _
"User ID=用户名;Password=密码;Initial Catalog=数据库名;Data Source=SQL服务器名"
'读取文件到内容
Set iStm = New ADODB.Stream
With iStm
.Type = adTypeBinary '二进制模式,如果是用text/ntext字段保存纯文本数据,则改用 adTypeText
.Open
.LoadFromFile "c:\test.doc"
End With

'打开保存文件的表
Set iRe = New ADODB.Recordset
With iRe
.Open "表", iConc, adOpenKeyset, adLockOptimistic
.AddNew '新增一条记录
.Fields("保存文件内容的字段") = iStm.Read
.Update
End With

'完成后关闭对象
iRe.Close
iStm.Close
End Sub

'从数据库中读取数据,保存成文件
Sub s_ReadFile()
Dim iStm As ADODB.Stream
Dim iRe As ADODB.Recordset
Dim iConc As String

'数据库连接字符串
iConc = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False" & _
";Data Source=\\xz\c$\Inetpub\zj\zj\zj.mdb"

'打开表
Set iRe = New ADODB.Recordset
iRe.Open "tb_img", iConc, adOpenKeyset, adLockReadOnly
iRe.Filter = "id=64"

if iRe("img").ActualSize>0 Then

'保存到文件
Set iStm = New ADODB.Stream
With iStm
.Mode = adModeReadWrite
.Type = adTypeBinary '二进制模式,如果是用text/ntext字段保存纯文本数据,则改用 adTypeText
.Open
.Write iRe("img")
.SaveToFile "c:\test.doc"
End With

'关闭对象
iStm.Close
End If

iRe.Close
End Sub
子陌红尘 2005-07-13
  • 打赏
  • 举报
回复
如果要从客户端将视频文件上传到服务器的数据库中保存,需要通过程序将视频文件转为二进制流然后通过调用SQL Server 2000的writetext函数写入数据库。
wudan8057 2005-07-13
  • 打赏
  • 举报
回复
采用复制的方法到目录:
1.映射
EXEC master..xp_cmdshell 'net use z:\\服务器名\路径 /user:登陆服务器用户名\登陆服务器用户密码
2.复制
EXEC master..xp_cmdshell 'copy 源文件路径 z:\'
3.删除映射
EXEC master..xp_cmdshell 'net use z:/delete'

net use 的使用方法可以参考windows帮助
子陌红尘 2005-07-13
  • 打赏
  • 举报
回复
上传至目录还是数据库?

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧