Help with paging through files in server
03-13-2006, 02:31 AM
|
Help with paging through files in server
|
Posts: 59
Location: North Borneo.
|
Hi,
Im having problem of paging through files in server. Since the file in server are image file (jpeg,gif), so if I load it in one page in one time, it might take too long to load (the system i'm working with will have more than 500 images files). Can anyone with this experience give me an idea on how to do this? a pseudocode might just help. Thanks. : 
__________________
$id ="waxxer";
$id = str_replace('x', 'l', $id);
echo $id;
echo " and Marj";
|
|
|
|
03-13-2006, 02:33 PM
|
Re: Help with paging through files in server
|
Posts: 5,942
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
|
Here's how I'd do it (roughly):
Gather up all of the file names using FSO.
Put each file name into a database (e.g. Access).
Retrieve from database (e.g. Access) and use the built-in recordset paging the recordset object requires to page through the images.
|
|
|
|
03-13-2006, 08:04 PM
|
Re: Help with paging through files in server
|
Posts: 59
Location: North Borneo.
|
PHP Code:
strDir=cStr(request.QueryString("dir"))
strPath=Server.MapPath("images\" & strDir)
strCmd = request.QueryString("cmd")
strFolder = request.QueryString("folder")
intTable=int(request.QueryString("size"))
strPage=request.QueryString("page")
What does these means ?
I'm studying this one code where it does'nt require a database at all. Those script up there are the one I dont understand. If you have time, take a look at the full script below...
PHP Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
'## Declaring variables
dim aDir, strDir, strPath, strCmd, strFolder, strName, strFile, strPage, pagenum
dim fso, MyFolder, FileObject, MyFiles, hidden, strStyle, sTemp, strImage
dim intFiles, intTotal, intTotalFiles, intTable, intImages, intOS, iCount
dim a, b, i, k, x, y, z
strDir=cStr(request.QueryString("dir"))
strPath=Server.MapPath("images\" & strDir)
strCmd = request.QueryString("cmd")
strFolder = request.QueryString("folder")
intTable=int(request.QueryString("size"))
strPage=request.QueryString("page")
'## Select the default view (details / thumbs)
if strPage="" then strPage="details"
strFile=cStr(request.QueryString("file"))
strDir=cStr(request.QueryString("dir"))
strPath=Server.MapPath("images\" & strDir)
i=strPath & "" & strFile
strName=request.QueryString("name")
'## Check OS in order to disable unavailable features in Linux
if left(Request.ServerVariables("ASP_OS"), 5)="Linux" then intOS=1
'## Set the table width to 700 as default (5 images)
if intTable="" or intTable=0 or isNull(intTable)=true then intTable=700
intImages=round(intTable/106-2)
'## Total files per page
intTotalFiles=int(intImages*intRows)
'## Remove ../ and \ from the folder string
if left(strDir, 3)="../" OR left(strDir, 3)=".." then strDir=""
if right(strDir, 1)="" then strDir = mid(strDir,1, len(strDir)-1)
'## Paging
PageNum = request.querystring("pagenum")
If PageNum="" or int(PageNum)=1 Then PageNum=1
iCount = (PageNum -1) * intTotalFiles
Set fso=Server.CreateObject("Scripting.FileSystemObject")
%>
<head>
<title>Image Archive</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="JavaScript" src="java.js" type="text/javascript"></script>
<!--#Include File="style2.asp"-->
<%if strPage<>"slide" then%>
</head>
<body>
<form name="form" id="form" method="post" action="default.asp?page=<%=strPage%>&dir=<%=strDir%>">
<%end if
if strPage="details" OR strPage="thumbs" then
Set MyFolder = fso.GetFolder(strPath)
Set MyFiles = MyFolder.Files
%>
<table class="table" width="700" border="0" cellpadding="0">
<tr class="title">
<td width="271"> Path: <strong onmouseover="a('Change directory');return true" onmouseout="b()">
<%response.write "<a href='?page="&strPage&"&size=" & intTable &"'>images:</a> "
'## Create an array in order to split the dir string for the menu
a=split(strDir, "", -1)
for i=0 to uBound(a)
if i=0 then
aDir=cStr(a(0))
else
aDir=aDir & "" & a(i)
end if
b=a(i)
response.write "<a href='?page="&strPage&"&dir=" & aDir & "&size=" & intTable &"'>" & a(i) & "</a>"
if not uBound(a)=i then response.write " "
next
%></strong></td>
<td width="93"> </td>
<td width="123"> </td>
<td width="122"><%if strPage="thumbs" then
'## Check for changes in table size (dropdown)
if ucase(trim(request.ServerVariables("REQUEST_METHOD")))="POST" then
response.redirect("?page="&strPage&"&size="&int(request.form("frmSize"))&"&dir="& strDir)
end if%>
<select name="frmSize" id="frmSize" onchange="form.submit()">
<option>Images per row</option>
<option value="600">4</option>
<option value="700">5</option>
<option value="900">6</option>
<option value="1000">7</option>
<option value="1100">8</option>
<option value="1200">9</option>
<option value="1300">10</option>
</select>
<%end if%></td>
<td width="79" align="center"><a onmouseover="a('List Details');return true" onmouseout="b()" onclick="" href="?page=details&dir=<%=strDir%>"><img src="icons/fileinfo.gif" alt="List Details" width="20" height="20" border="0" align="middle" /></a> <a onmouseover="a('List Thumbnails');return true" onmouseout="b()" href="?page=thumbs&dir=<%=strDir%>"><img src="icons/find.gif" alt="List Thumbnails" width="20" height="20" border="0" align="middle" /></a> <a onmouseover="a('Slideshow');return true" onmouseout="b()" onclick="slideshow('<%=replace(strDir, "\", "/")%>')" href="#"><img src="icons/slideshow.gif" alt="Slideshow" width="20" height="20" border="0" align="middle" /></a></td>
</tr>
<tr class="title">
<td width="271"> Filename</td>
<td width="93"> Size</td>
<td width="123"> Date Modified</td>
<td width="122"> Date Created</td>
<td width="79" align="center"> <%if blnSecurity=true then response.write "Actions"%></td>
</tr>
<%if strDir<>"" then %>
<tr>
<td colspan="5"> <a onmouseover="a('Parent directory');return true" onmouseout="b()" href="?page=<%=strPage%>&dir=<%=replace(strDir, myfolder.name, "")%>&size=<%=intTable%>"><img src="icons/_UP1LEVEL.GIF" width="16" height="16" border="0" align="middle" alt="" />
..</a></td>
</tr>
<%strStyle=2
end if
'## If the folder is hidden then hide the content
Set hidden = fso.GetFolder(strPath)
if hidden.attributes=18 AND blnLogin=false then%>
<tr>
<td colspan="5"> The content of this folder is hidden. Please login
in order to view it.</td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<%
'## Display the folder content
else
y=0
For Each i in MyFolder.subfolders
if i.attributes<>18 OR (blnLogin=true AND i.attributes=18) then
y=y+1
strStyle = strStyle + 1
If strStyle > 1 Then strStyle = 0%>
<tr <%if strstyle=0 then response.write ("class=""list""")%>> <% if strDir<>"" then
sTemp=strDir & "\" & i.name
else
sTemp=i.name
end if%>
<td width="271"> <%
'## Show different folder icon if the folder is hidden
if i.attributes=18 then%> <img src="icons/icon_folder_locked.GIF" width="16" height="16" border="0" align="middle" alt="" />
<%else%> <img src="icons/_FOLDER.GIF" width="16" height="16" border="0" align="middle" alt="" />
<%end if%><a onmouseover="a('Change directory');return true" onmouseout="b()" href="?page=<%=strPage%>&dir=<%=sTemp%>&size=<%=intTable%>" target="_self">
<%=i.name%></a></td>
<td align="right" width="93"> <%=formatnumber(i.Size/1024, 2)%> KB </td>
<td width="123"><%=i.DateLastModified%></td>
<td width="122"><%=i.DateCreated%></td>
<td width="79"> <%if blnSecurity=true then%> <img src="icons/copy.gif" alt="Copy folder" width="19" height="19" align="middle" style="cursor:pointer" onclick="PromptCopy('','<%=strDir%>', '<%=i.name%>')" onmouseover="a('Copy folder'); return true" onmouseout="b()" />
<img src="icons/ren.gif" alt="Rename folder" width="20" height="20" align="middle" style="cursor:pointer" onclick="PromptRename('','<%=strDir%>', '<%=i.name%>')" onmouseover="a('Rename folder'); return true" onmouseout="b()" />
<img src="icons/del.gif" alt="Delete folder" width="20" height="20" align="middle" style="cursor:pointer" onclick="PromptDelete('','<%=strDir%>', '<%=i.name%>')" onmouseover="a('Delete folder'); return true" onmouseout="b()" /><%end if%>
</td>
</tr>
<%
end if
next
if strPage="thumbs" then
else
y=0
'## Loop through all the files in the current folder
For Each i in MyFolder.files
if FileType(i.name)=true then
'## Used to count files in folder
y=y+1
'## change background color on 0
strStyle = strStyle + 1
If strStyle > 1 Then strStyle = 0%>
<tr <%if strstyle=0 then response.write ("class=""list""")%>>
<td width="271"> <a onmouseover="a('Show image');return true" onmouseout="b()" href="javascript:Preview('<%=i.name%>', '<%=replace(strDir, "\", "/")%>');" target="_self"><%if intOS<>1 then%><img src="icons/<%=left(i.type,3)%>.GIF" width="16" height="16" border="0" align="middle" alt="" /><%end if%>
<%=i.name%></a></td>
<td align="right" width="93"><%=formatnumber(i.Size/1024, 2)%> KB </td>
<td width="123"><%=i.DateLastModified%></td>
<td width="122"><%=i.DateCreated%></td>
<td width="79"> <%if blnSecurity=true then%> <img src="icons/copy.gif" alt="Copy image" width="19" height="19" align="middle" style="cursor:pointer" onclick="PromptCopy('<%=i.name%>','<%=strDir%>','')" onmouseover="a('Copy file'); return true" onmouseout="b()" />
<img src="icons/ren.gif" alt="Rename image" width="20" height="20" align="middle" style="cursor:pointer" onclick="PromptRename('<%=i.name%>','<%=strDir%>','')" onmouseover="a('Rename file'); return true" onmouseout="b()" />
<img src="icons/del.gif" alt="Delete image" width="20" height="20" align="middle" style="cursor:pointer" onclick="PromptDelete('<%=i.name%>','<%=strDir%>','')" onmouseover="a('Delete file'); return true" onmouseout="b()" /><%end if%></td>
</tr>
<%
end if
next
end if%>
</table>
</form><%end if
if strPage="thumbs" AND (hidden.attributes<>18 OR blnLogin=true) then
Set hidden = Nothing %>
<table class="table" border="0" cellspacing="0" cellpadding="5">
<tr><%
Set MyFolder = fso.GetFolder(strPath)
For Each i in MyFolder.files
x=x+1
if FileType(i.name)<>true then
x=x-1
z=z+1 'Images to exclude
k=k+i.size
end if
if iCount < x AND FileType(i.name)=true then
strImage = "images/"
if strDir="" then
strImage = strImage & i.name
else
strImage = strImage & strDir & "/" & i.name
end if%>
<td align="center" valign="bottom"><a onmouseover="a('Show image');return true" onmouseout="b()" href="javascript:Preview('<%=i.name%>', '<%=replace(strDir, "\", "/")%>')" target="_self"><% if blnComponent=false then
response.write "<img src="""&strImage&""" border=""0"" "& ImageResize(Server.MapPath(strImage) , 120, 120)&" alt="""" />"
else
response.write "<img src=""img.asp?dir="&strDir&"&file="&i.name&""" border=""0"" alt="""" />"
end if%><br /><%if blnFileName=true then response.write left(i.name, len(i.name)-4)%></a><%
if blnSecurity=true then%><br />
<img src="icons/copy.gif" alt="Copy image" width="19" height="19" align="middle" style="cursor:pointer" onclick="PromptCopy('<%=i.name%>','<%=strDir%>','')" onmouseover="a('Copy file'); return true" onmouseout="b()" />
<img src="icons/ren.gif" alt="Rename image" width="20" height="20" align="middle" style="cursor:pointer" onclick="PromptRename('<%=i.name%>','<%=strDir%>','')" onmouseover="a('Rename file'); return true" onmouseout="b()" />
<img src="icons/del.gif" alt="Delete image" width="20" height="20" align="middle" style="cursor:pointer" onclick="PromptDelete('<%=i.name%>','<%=strDir%>','')" onmouseover="a('Delete file'); return true" onmouseout="b()" />
<%end if%></td>
<%
end if '---
If x Mod intImages = 0 Then Response.Write "</tr><tr>"
If x >= iCount + intTotalFiles then
Exit For
End if
next%>
<td></td></tr>
</table>
<br /><%
intFiles=int(MyFolder.Files.Count-z)
if intTotalFiles<intFiles then%>
<table border="0" cellpadding="0" class="table">
<tr align="right">
<td colspan="4"> <%
'######### LEFT ########
If Clng(pagenum) > 1 Then
Response.Write "[<a href='?page="&strPage&"&dir=" & replace(aDir, " ", "%20") & "&size=" & intTable & "&pagenum=1'><<</a>]"
Else
Response.Write "[<<]"
End If
response.write " "
If Clng(pagenum) > 1 Then
Response.Write "[<a href='?page="&strPage&"&dir=" & replace(aDir, " ", "%20") & "&size=" & intTable & "&pagenum=" & pagenum - 1 & "'><</a>]"
Else
Response.Write "[<]"
End If
'######### NUM ########
intTotal = MyFolder.Files.Count
y = round(intTotal/intTotalFiles+0.4)
For x = 1 to y
if x=int(PageNum) then
Response.Write " <strong><a href='?page="&strPage&"&dir=" & replace(aDir, " ", "%20") & "&size=" & intTable & "&pagenum=" & x & "'>" & x & "</a></strong> "
if x<>y then response.write "|"
else
Response.Write " <a href='?page="&strPage&"&dir=" & replace(aDir, " ", "%20") & "&size=" & intTable & "&pagenum=" & x & "'>" & x & "</a> "
if x<>y then response.write "|"
end if
Next
'######### RIGHT ########
If Clng(pagenum) < Clng(y) Then
Response.Write "[<a href='?page="&strPage&"&dir=" & replace(aDir, " ", "%20") & "&size=" & intTable & "&pagenum=" & pagenum + 1 & "'>></a>] "
Else
Response.Write "[>]"
End If
If Clng(pagenum) < Clng(y) Then
Response.Write "[<a href='?page="&strPage&"&dir=" & replace(aDir, " ", "%20") & "&size=" & intTable & "&pagenum=" & round(intTotal/intTotalFiles+0.4) & "'>>></a>] "
Else
Response.Write " [>>]"
End If
response.write "<br /><br />"
end if
%> </td>
</tr>
</table><%end if
if blnStatusBar=true then%>
<table border="0" cellpadding="0" class="title table">
<tr>
<td width="150"> <%=intFiles%> object(s) </td>
<td width="198" align="right"> <%=formatnumber(int(MyFolder.Size-k)/1024, 2) & " KB"%> </td>
<td width="139"> </td>
<td width="127" align="right"> <img src="icons/imgfolder.gif" width="18" height="18" align="middle" alt="" />Image Archive </td>
</tr>
</table><%end if%>
<table border="0" cellpadding="0" class="table">
<tr align="center">
<td colspan="4"> Copyright 2005 Nivcin Development. All Rights Reserved.
</td>
</tr>
</table>
<br />
<%elseif strPage="slide" then%>
<script>
document.title='Press F11 for fullscreen'
var Pic = new Array()
<%
x=-1
Set MyFolder = fso.GetFolder(strPath)
For Each i in MyFolder.files
x=x+1
response.write ("Pic[" & x & "] = 'images/" & strDir & "/" & i.name & "';") & vbCrLf
next
%>
var t
var j = -1
var p = Pic.length
a = new Image()
function runSlideShow(){
j = j+1
if (j > (p-1)) j=0
document.images.SlideShow.src = Pic[j]
t = setTimeout('runSlideShow()', <%=intTimer%>)
}
</script><body onLoad="runSlideShow()" leftmargin="0px" rightmargin="0px" topmargin="0px" bottummargin="0px" marginheight="0px" marginwidth="0px">
<img alt="Click to close" name='SlideShow' width="100%" border="0" align="absmiddle" id="SlideShow" onclick="window.close()" />
<%end if%>
</body>
</html><%
if strCmd="delete" then '------------------------------------------------ DELETE FILE
if strFile<>"" OR strFolder<>"" AND blnSecurity=true then
if strFile<>"" then
Set fileObject = fso.GetFile(strPath & "" & strFile)
elseif strFolder<>"" then
Set fileObject = fso.GetFolder(strPath & "" & strFolder & "")
end if
fileObject.Delete
Set fileObject = Nothing
Set fso = Nothing
end if
response.redirect ("default.asp?page="&strPage&"&dir=" & strDir)
elseif strCmd="copy" then '------------------------------------------------ COPY FILE
if strFile<>"" OR strFolder<>"" AND blnSecurity=true then
Set fso = CreateObject("Scripting.FileSystemObject")
if strFolder="" then
if fso.FileExists (strPath & "" & "copy of " & strFile)=false then
Set fileObject = fso.GetFile(strPath & "" & strFile)
fileObject.Copy (strPath & "" & "copy of " & strFile),false
end if
elseif strFolder<>"" then
if fso.FolderExists (strPath & "" & "copy of " & strFolder)=false then
Set fileObject = fso.GetFolder(strPath & "" & strFolder & "")
fileObject.Copy (strPath & "" & "copy of " & strFolder),false
end if
end if
Set fileObject = Nothing
Set fso = Nothing
end if
response.redirect ("default.asp?page="&strPage&"&dir=" & strDir)
elseif strCmd="rename" then '--------------------------------------------- RENAME FILE
if strFile<>"" OR strFolder<>"" AND blnSecurity=true then
Set fso = CreateObject("Scripting.FileSystemObject")
if strFolder="" then
if fso.FileExists (strPath & "" & strName)=false then
fso.MoveFile strPath & "" & strFile, strPath & "" & strName
end if
elseif strFolder<>"" then
if fso.FolderExists (strPath & "" & strName)=false then
fso.MoveFolder strPath & "" & strFolder, strPath & "" & strName
end if
end if
Set fileObject = Nothing
Set fso = Nothing
end if
response.redirect ("default.asp?page="&strPage&"&dir=" & strDir)
end if
'## What files will be displayed
function FileType(strFile)
strFile = lcase(right(strFile, 3))
select case strFile
case "jpg" strFile=true
case "gif" strFile=true
case "png" strFile=true
case "bmp" strFile=true
case "peg" strFile=true 'jpeg
case "jpe" strFile=true 'jpeg
end select
FileType=strFile
end function
Set MyFolder = Nothing
Set fso = Nothing
__________________
$id ="waxxer";
$id = str_replace('x', 'l', $id);
echo $id;
echo " and Marj";
|
|
|
|
03-13-2006, 10:07 PM
|
Re: Help with paging through files in server
|
Posts: 5,942
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
|
That's the trouble with code from other sites: it almost never works. That one would never even execute properly (it's missing a <% timestop about 5 lines down).
The lines you don't understand gather querystrings from the form post later on in the code (why not just pass them as hidden form elements, I don't know), and the strPath uses Server.MapPath to figure out where the image directory is on the server in terms of a path and folder e.g. C:\inetpub\wwwroot\yoursite.com\images). This will allow the script to read the images folder and extract the appropriate info.
|
|
|
|
03-16-2006, 05:58 AM
|
Re: Help with paging through files in server
|
Posts: 95
|
I've recently had this trouble. I too tried taking free scripts from other sites. These almost never worked with out having to alter it. And then never as i needed.
The way i solved it was good old fashioned elbow grease. I got a book and online tutorials and worked through it step by step.
It wasnt the quickest method or the easyiest but its the most rewarding as you have complete knowledge of what you code is doing and how to ammend it.
sorry its not the answer your looking for, but it the way i would solve your problem. no point having code that you dont understand
|
|
|
|
03-16-2006, 01:08 PM
|
Re: Help with paging through files in server
|
Posts: 5,942
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
|
higginbt is right. Most free scripts are flat-out garbage. That one doesn't look too bad, but if it were me I'd deconstruct it to see what was going on.
Anyway, let us know how it turns out.
|
|
|
|
|
« Reply to Help with paging through files in server
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|