
Originally Posted by
Twey
Yes, in theory. I'm talking only about what's possible, though, not necessarily what's been implemented.
That was a little cryptic, guess I'll need to do a search on that soon, parse trees. Getting back to the topic of this thread, getpics.asp - it has come to my attention that some asp enabled servers are not configured to report .Type as "Image" on image files so, a more bullet proof method of testing for image files would be good. There are routines for analyzing the first 1000 or so bytes of a fie to determine this but, I think that is overkill if, for the purposes of this exercise, we can assume that the webmaster has uploaded files that end in .gif, .png and .jpg (upper or lower case), that are valid images, in good faith to the directory in question. So, regular expression to the rescue! Changes/additions red:
getpics.asp:
Code:
<%
' The Runtime code:
' Create some asp variables for
Dim strPath 'Path of directory
Dim objFSO 'FileSystemObject variable
Dim objFolder 'Folder variable
Dim objItem 'Variable used to loop through the contents of the folder
' You could just as easily read this from some sort of input
' NOTE: As currently implemented, this needs to end with the /
strPath = "./"
' Create our FSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' Get a handle on our folder
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
'Create some javascript variables
%>
var counter=0
var galleryarray=new Array()
<%
'Selecting only images
Set RegExObj = New RegExp
With RegExObj
.Pattern = "gif|jpg|png"
.IgnoreCase = True
End With
For Each objItem In objFolder.Files
If RegExObj.Test(Right(objItem.Name, 3)) Then
'Add each one and their date to the array using javascript
%>
galleryarray[counter]=["<%= objItem.Name %>", "<%= objItem.DateCreated %>"]
counter++
<%
End If
Next 'objItem
' All done! Kill off our asp object variables.
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
Set RegExObj = Nothing
%>
Bookmarks