100分求解图片FTP上传后前台用户立刻能够看到问题!

farfly 2004-06-11 09:22:32
现做一图库网站,碰到一问题:

操作:通过FTP软件上传图片文件至指定目录;
要求:希望每上传一个图片文件后访问用户最好立刻能够在前台页面看到新上传的文件;

我的思路:

方法一:用户每访问一次就遍历一下指定目录下所有文件并显示出来
优缺点:这样能够满足用户立刻看到最新上传文件的要求,而且管理员也无须额外操作,只管上传文件即可。

但每一个用户访问的时候速度慢(遍历目录操作很费时),带来很不好的访问体验。

方法二:管理员每上传一个图片文件后就通过后台将最新变动形成静态页面。
优缺点:由于用户访问的是静态页面,访问速度非常快(这一点借鉴了新闻发布系统的思路),但费时的感受

转嫁给了管理员。

如何做到用户访问速度快,而管理员也感觉操作快呢?请指教!
...全文
185 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
farfly 2004-06-22
  • 打赏
  • 举报
回复
谢谢cat_hsfz,当初我也这么想,但后来感觉太麻烦了。还是用ASP做了一个上传文件的页面,每上传完一个文件同时在数据库里更新这个文件的状态(表明对应路径里有无内容)和最后更新时间。
farfly 2004-06-22
  • 打赏
  • 举报
回复
谢谢skywolfy,呵呵,上传文件事先有设定名称于数据库内的。
cat_hsfz 2004-06-20
  • 打赏
  • 举报
回复
如果你的FTP服务支持插件(例如Serv-U),你可以自己写一个插件来负责更新页面,或者更新数据库——然后你的页面根据数据库更新。否则,还是自己写一个FTP服务软件吧,呵呵……
skywolfY 2004-06-20
  • 打赏
  • 举报
回复
上传图片不可能马上就看得到,除非上传文件事先有设定名称。放在数据库中应该能满足条件
程序设定读取哪个字段,而字段对应的内容可以变化
alcoholwang 2004-06-19
  • 打赏
  • 举报
回复
不知道你用的FTP软件是什么。

如果是SERV-U,我有个办法不知道行不行。

让SERV-U按照每天生成日志文件,然后用FSO检测SERV-U日志。
SERV-U的上传格式是:
[4] Sat 19Jun04 00:17:56 - (010080) Received file e:\测试\test.gif successfully (710 Bytes/sec - 2375 Bytes)

这样检测到带[4]这行,然后分析一下上传到的是不是图片目录,是不是图片文件。
然后读取数据库,搜索一下图片文件名,如果找到记录,如果是相同的就不做什么操作,如果不同,就将图片文件的文件名插入到数据库。

前台通过数据库来列出图片文件。

如果觉得用户每次访问就检测效率太低,那就建立一个文件,作为时间检测文件,FSO判断文件修改时间和当前时间,设定一个间隔值,如果大于间隔值,就对日志文件做检测。

这样的好处是不用每次都遍历图片目录,而简化到对日志,时间检测文件的检测。



当然,做个后台程序,通过WEB上传,然后将信息写入数据库,通过数据库来列表图片文件,这个效率应该是最好的。

使用数据库方便管理。
farfly 2004-06-19
  • 打赏
  • 举报
回复
非常感谢 alcoholwang(工业酒精) ,我试试看!

farfly 2004-06-18
  • 打赏
  • 举报
回复
非常感谢 webdevelop(网上飞),但每次用户访问都这样调是不是慢了点?呵呵,第一次我就这样实现的,但客户不能接爱。于是换成第二种实现方式(生成静态前台文件),但客户嫌自己又慢了,现在陷入二难境地啊!如何前后台都快一点呢?
webdevelop 2004-06-11
  • 打赏
  • 举报
回复
简单啊,把上传的目录放到WEB目寻里
用ASP的FSO调出来。

参考代码
Domain=Request.ServerVariables("SERVER_NAME")
soFilePath=Request.ServerVariables("PATH_INFO")
soFilePath=lcase(left(soFilePath,instrRev(soFilePath,"/")))
sowinpath=Domain&soFilePath

Set MyFile=Server.CreateObject("Scripting.FileSystemObject")
if request.form("result")="del" then
Num=request.form("FileName").count
for x=1 to Num
if MyFile.FileExists(Server.Mappath("..")&"\Files\UpFile\"&request.form("FileName")(x)&"") then
MyFile.DeleteFile(Server.Mappath("..")&"\Files\UpFile\"&request.form("FileName")(x)&"")
end if
next
end if
Page=request.querystring("page")
if Page<=1 or Page="" then Page=1
PageSize=15
Domain=Request.ServerVariables("SERVER_NAME")
soFilePath=Request.ServerVariables("PATH_INFO")
soFilePath=lcase(left(soFilePath,instrRev(soFilePath,"/")))
socount=len(soFilePath)
soFilePath=lcase(left(soFilePath,socount-1))
soFilePath=lcase(left(soFilePath,instrRev(soFilePath,"/")))
sowinpath="http://"&Domain&soFilePath
FileCount=0
Set FileFolder=MyFile.GetFolder(Server.MapPath("..")&"\Files\UpFile")
for each TheFile in FileFolder.Files
FileCount=FileCount+1
AFileSize=TheFile.size+AFileSize
next
%>
<html>
<LINK href=css/css.css rel=stylesheet>
<body bgcolor="#FFFFFF">
<form method=post action="">
<table width="100%" border="0" cellspacing="1" cellpadding="0" align="center">
<tr bgcolor="#FFFFFF" valign="middle" align="center">
<td width="300%" height="2" colspan="3" > <table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#97C893">
<tr bgcolor="#F7FFF4">
<td width="34%" height=20 align=center>文件名</td>
<td width="35%" height=20 align=center>上传时间</td>
<td width="20%" height=20 align=center>文件大小</td>
<td width="11%" height=20 align=center>删除</td>
</tr>
<%
i=0
for each thing in FileFolder.Files
i=i+1
if CCount>=PageSize then
exit for
elseif i>PageSize*(Page-1) then
CCount=CCount+1

%>
<tr bgcolor="#F7FFF4">
<td width="34%" height=24 class="small1"> <div align="left">
<table width="92%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="18%"><table width="30" height="30" border="0" cellpadding="0" cellspacing="1" bgcolor="#C9C9C9">
<tr>
<td bgcolor="#FFFFFF"><a href="../Files/UpFile/<%=thing.name%>" target="_blank"><img src="../Files/UpFile/<%=thing.name%>" width="30" height="30" border="0"></a></td>
</tr>
</table></td>
<td width="82%"><a href=../Files/UpFile/<%=thing.name%> target=_blank>
<%=thing.name%></a></td>
</tr>
</table>
</div></td>
<td width="35%" height=24 align=center><%=thing.DateLastModified%></td>
<td width="20%" height=24 align=center><%=thing.Size&"(bt)"%></td>
<td width="11%" height=24 align=center> <input type="checkbox" name=FileName value=<%=thing.Name%>></td>
</tr>
<%
end if
next
%>
<tr bgcolor="#F7FFF4">
<td height=20 colspan=5 align=right> <div align="center">共有<font color=red><b><%=FileCount%></b></font>个文件;
占用<font color=red><b><%=AFileSize/1024%></b></font><font color=#FF0000><b>K</b></font>空间    
<input type=hidden value=del Name=result>
<input type="checkbox" name="chkall" onclick="CheckAll(this.form)">
选中所有
<input type=submit value=删除 onclick="return Del()" class=Anbut1>
</div></td>
</tr>
<tr bgcolor="#F7FFF4">
<td height=20 colspan=5>
<%
PageCount=int(FileCount/PageSize)+1
for i=1 to PageCount
response.write "<a href=?Page="&i&"><b>第"&i&"页</b></a> "
next
%>
<!--#include file = name.asp-->
</td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
zzlcn 2004-06-11
  • 打赏
  • 举报
回复
没有两全齐美的
farfly 2004-06-11
  • 打赏
  • 举报
回复
自已顶一下

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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