关于存储文件的问题,抉择很艰难!高手给方案!

ponycsdn 2003-12-15 08:15:09
我再做办公网络b/s架构局域网用户使用。
在文件上传这个方面的时候我抉择苦难。到底是数据库存文件呢?还是文件夹存文件。我问过专业系统分析员说数据库存储比较灵活,可移植,多采取此方法。
但是有不利的方面就是消耗太多空间。

我想把下载的音乐,电影,A片(American)都存起来。当然还有表格,办公的东东不怎么占地方。

到底怎么办呢?我想一定是非此即彼。请赐教!
...全文
28 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ponycsdn 2003-12-16
  • 打赏
  • 举报
回复
我想过了,先做数据库版本的遇到问题再改,youngby(诗人:$(!@杰拉*…^%正版男生#@) 告诉我去掉日志。减少空间负担。不知可行否?
zjcxc 元老 2003-12-16
  • 打赏
  • 举报
回复
一般是这样考虑的.

如果要存储的文件多,数量大.就将文件存储到磁盘上.
数据库中保存文件的编号,搜索的关键字等文件信息.
缺点是不方便程序的移植.

如果存储的文件较少,数量不多.就将文件存储到数据库中.
方便移植.
zjcxc 元老 2003-12-16
  • 打赏
  • 举报
回复
'==================================================================--
'
' 用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
%>

samuelpan 2003-12-15
  • 打赏
  • 举报
回复
文件夹好,看看windows share point server吧
txlicenhe 2003-12-15
  • 打赏
  • 举报
回复
各有各的优点吧。
武断地说用哪一种好象都不好。
如果供局域网内使用的话,建议用文件夹存文件名。路径设为系统参数的形式。

http://expert.csdn.net/Expert/topic/2403/2403509.xml?temp=.2279474
主  题: 交流--数据库中存/取文件
作  者: zjcxc (邹建)


youngby 2003-12-15
  • 打赏
  • 举报
回复
//得到提交的文件
Stream fileDataStream = MyFile.PostedFile.InputStream;

//得到文件大小
int fileLength = MyFile.PostedFile.ContentLength;

//创建数组
byte[] fileData = new byte[fileLength];

//把文件流填充到数组
fileDataStream.Read(fileData,0,fileLength);

//得到文件名字
string fileTitle = MyFileName.Value;

//得到文件类型
string fileType = MyFile.PostedFile.ContentType;

//构建数据库连接,SQL语句,创建参数
SqlConnection connection = new SqlConnection("Server=.;uid=sa;pwd=;Database=TestUploadFile");
SqlCommand command = new SqlCommand ("INSERT INTO TestFiles (MyFileName,MyFile,FileType)" +
"VALUES (@MyFileName,@MyFile,@FileType)", connection);

SqlParameter paramTitle = new SqlParameter ("@MyFileName", SqlDbType.VarChar,35);
paramTitle.Value = fileTitle;
command.Parameters.Add(paramTitle);

SqlParameter paramData = new SqlParameter ("@MyFile", SqlDbType.Image);
paramData.Value = fileData;
command.Parameters.Add(paramData);

SqlParameter paramType = new SqlParameter ("@FileType", SqlDbType.VarChar,25);
paramType.Value = fileType;
command.Parameters.Add(paramType);

//打开连接,执行查询
connection.Open();
command.ExecuteNonQuery();
connection.Close();

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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