PDA

View Full Version : [DHTML] getpics.asp



jscheuer1
06-19-2006, 07:41 AM
1) CODE TITLE: getpics.asp

2) AUTHOR NAME/NOTES: jscheuer1, freely adapted from:

http://www.asp101.com/samples/dir_list.asp

3) DESCRIPTION: An ASP/VB/JSCRIPT hybrid that is a drop in replacement for getpics.php for servers that have asp, but not php, available. For use with PHP Album script (http://dynamicdrive.com/dynamicindex4/php-photoalbum.htm). Use just like getpics.php, replacing this line in PHP Album script:


<script src="http://www.mysite.com/gallery/getpics.php" type="text/javascript"></script>

with this:


<script src="http://www.mysite.com/gallery/getpics.asp" type="text/javascript"></script>

4) URL TO CODE:

or, ATTACHED BELOW (see #3 in guidelines below):

Simply save the below as 'getpics.asp' and upload it to your image directory just as instructed to for getpics.php.
Do not edit the file! Comments are developers notes only, not instructions for editing!


<%
' 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
For Each objItem In objFolder.Files
If Right(objItem.Type, 5)="Image" 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
%>

Twey
06-19-2006, 03:45 PM
I didn't know you knew ASP. :)

I'll write a JSP one when my host gets its ass in gear and sorts out its servers...

jscheuer1
06-19-2006, 09:38 PM
I didn't but, they are all pretty straightforward file accessing commands used in a variety of these 'directory listing' script/pages that abound on the web as beginner examples. I just got rid of all of the HTML 'window dressing' and some unnecessary code, added the client side javascript and a little more server side VBscript to make it do the deed.

But, I am getting excited about asp, not because it is so good, but because it is available on a site I master that needs a way to do template pages and php is not available.

Twey
06-20-2006, 12:24 AM
What other languages are available for writing ASP pages?

mwinter
06-20-2006, 12:44 AM
What other languages are available for writing ASP pages?JScript, to name a relatively obvious one. Perl too, apparently, given the right support. I don't know about any others, but ASP isn't tied to any particular language, so it may only be a matter of developing an interface for a given language (though I'm not going to pretend that that would be trivial).

For ASP.NET, any .NET-compatible language can be used: Visual Basic .NET, JScript .NET, C#, and Managed C++.

Mike

Twey
06-20-2006, 01:07 AM
so it may only be a matter of developing an interface for a given language (though I'm not going to pretend that that would be trivial).
Yeah... "only?" :)

I'm aware of the ASP.NET ones, I use C# in ASP.NET occasionally.

jscheuer1
06-20-2006, 03:30 AM
I think the language just has to be available on the server and either declared for the page at the very top:


<%@ LANGUAGE=VBScript %>

or used in a script tag with the runat=server attribute:


<SCRIPT LANGUAGE=JAVASCRIPT RUNAT=SERVER>
var bob='bing'
for (var i_tem = 0; i_tem < 3; i_tem++)
response.write("I am server-side JavaScript using the SCRIPT tag " + bob + "<P>");
</SCRIPT>

These are just from examples I have run across. The default language generally is VBscript. The thing I am coming to terms with now is determining how much if any communication can take place among the various languages on a page. It is relatively easy to communicate from server side to client side however, just as I did in the getpics.asp code. Another biggie is that it appears that although, say you are using server side Jscript. Things like the date object are available but not, apparently, the window and probably nothing like getElementById either, making things rather limited but, as compensation, there are includes, dbase and virtually bullet proof query string info hand offs.

Twey
06-20-2006, 02:16 PM
Things like the date object are available but not, apparently, the window and probably nothing like getElementById either, making things rather limited but, as compensation, there are includes, dbase and virtually bullet proof query string info hand offs.Elements and windows are client-side objects. Code running on the server has no access to them -- in fact, it doesn't even know they exist. No DOM-like abstraction of HTML is available, although parse trees are possible.

jscheuer1
06-20-2006, 09:28 PM
No DOM-like abstraction of HTML is available, although parse trees are possible.

Parse trees? Does this give any access to the parsed document - read and/or write? If not, what does it do? In either case how does it work?

Twey
06-20-2006, 09:34 PM
Does this give any access to the parsed document - read and/or write?Yes, in theory. I'm talking only about what's possible, though, not necessarily what's been implemented.

jscheuer1
06-21-2006, 05:55 AM
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:

<%
' 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
%>