Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying images in a table from a folder 1

Status
Not open for further replies.

Ragol1

Programmer
Oct 25, 2001
315
US
I have a bunch of pic's jpg and gifs in a folder which keeps getting updated with new ones so its growing and growing, I display these by editind th epage each time I add another picture but what I want is to just upload the picture to the folder and have the page read it.
I use this code to display the picture and have a pop up.

I can live without the Alt on these and the pop up if I have to but I would like to keep both.

I just want to diplay these pics in a table 4 wide and 8 or 10 deep then move to the next page.

<script>
function popUp1(URL1) {
New1 = open(URL1 , &quot;New1&quot;, &quot;toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=295,height=230,screenX=50,screenY=50,left=50,top=50&quot;);
}
</script>
<div align=&quot;left&quot;><a href=&quot;javascript:popUp1('Memberpics/docg.jpg');&quot;><img src=&quot;Memberpics/docg.jpg&quot; width=&quot;140&quot; height=&quot;100&quot; alt=&quot;Doc&quot; border=&quot;0&quot;></a></div>


Any Ideas.

Nick
 
This is code goheat came up with...I've modified it to show the images & the popup as you need.

This should get you started...

Code:
<%
' Change the DIRECTORY to point to any virtual directory of your choice.
CONST DIRECTORY = &quot;/Memberpics&quot; ' relative path in virtual directories

' Specify one of these constants for &quot;sortBy&quot;...
CONST FILE_NAME = 0
CONST FILE_EXT = 1
CONST FILE_TYPE = 2
CONST FILE_SIZE = 3
CONST FILE_CREATED = 4
CONST FILE_MODIFIED = 5
CONST FILE_ACCESSED = 6

' get requested sort order, if not first time here...
' (forward by name is default)
req = Request(&quot;sortBy&quot;)
If Len(req) < 1 Then sortBy = 0 Else sortBy = CInt(req)
req = Request(&quot;priorSort&quot;)
If Len(req) < 1 Then priorSort = -1 Else priorSort = CInt(req)

'
' did user ask for same sort? to reverse the order?
' but if so, then zap priorSort so clicking again will do forward!
If sortBy = priorSort Then
    reverse = true
    priorSort = -1
Else
    reverse = false
    priorSort = sortBy
End If

' now start the *real* code...
'
path = Server.MapPath( DIRECTORY )

Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set theCurrentFolder = fso.GetFolder( path )
Set curFiles = theCurrentFolder.Files
'
' And now a loop for the files
'
Dim theFiles( )
ReDim theFiles( 500 ) ' arbitrary size!
currentSlot = -1 ' start before first slot

' We collect all the info about each file and put it into one
' &quot;slot&quot; in our &quot;theFiles&quot; array.
'
For Each fileItem in curFiles
    fname = fileItem.Name
    fext = InStrRev( fname, &quot;.&quot; )
    If fext < 1 Then fext = &quot;&quot; Else fext = Mid(fname,fext+1)
    ftype = fileItem.Type
    fsize = fileItem.Size
    fcreate = fileItem.DateCreated
    fmod = fileItem.DateLastModified
    faccess = fileItem.DateLastAccessed
    currentSlot = currentSlot + 1
    If currentSlot > UBound( theFiles ) Then
        ReDim Preserve theFiles( currentSlot + 99 )
    End If
    ' note that what we put here is an array!
    theFiles(currentSlot) = Array(fname,fext,ftype,fsize,fcreate,fmod,faccess)
Next
'
' files are now in the array...
'
' As noted, it is actually an ARRAY *OF* ARRAYS. Which makes
' picking the column we will sort on easier!
'
' ...size and sort it...
fileCount = currentSlot ' actually, count is 1 more, since we start at 0
ReDim Preserve theFiles( currentSlot ) ' really not necessary...just neater!

' First, determine which &quot;kind&quot; of sort we are doing.
' (VarType=8 means &quot;string&quot;)
'
If VarType( theFiles( 0 )( sortBy ) ) = 8 Then
    If reverse Then kind = 1 Else kind = 2 ' sorting strings...
Else
    If reverse Then kind = 3 Else kind = 4 ' non-strings (numbers, dates)
End If

'
' A simple bubble sort for now...easier to follow the code...
'
For i = fileCount TO 0 Step -1
    minmax = theFiles( 0 )( sortBy )
    minmaxSlot = 0
    For j = 1 To i
        Select Case kind ' which kind of sort are we doing?
        ' after the &quot;is bigger/smaller&quot; test (as appropriate),
        ' mark will be true if we need to &quot;remember&quot; this slot...
        Case 1 ' string, reverse...we do case INsensitive!
            mark = (strComp( theFiles(j)(sortBy), minmax, vbTextCompare ) < 0)
        Case 2 ' string, forward...we do case INsensitive!
            mark = (strComp( theFiles(j)(sortBy), minmax, vbTextCompare ) > 0)
        Case 3 ' non-string, reverse ...
            mark = (theFiles( j )( sortBy ) < minmax)
        Case 4 ' non-string, forward ...
            mark = (theFiles( j )( sortBy ) > minmax)
        End Select
        ' so is the current slot bigger/smaller than the remembered one?
        If mark Then
            ' yep, so remember this one instead!
            minmax = theFiles( j )( sortBy )
            minmaxSlot = j
        End If
    Next
    ' is the last slot the min (or max), as it should be?
    If minmaxSlot <> i Then
        ' nope...so do the needed swap...
        temp = theFiles( minmaxSlot )
        theFiles( minmaxSlot ) = theFiles( i )
        theFiles( i ) = temp
    End If
Next
' Ta-da! The array is sorted!
'
%>
<FORM Name=&quot;doSort&quot; Method=&quot;Get&quot;>
<INPUT Type=Hidden Name=priorSort Value=&quot;<% = priorSort %>&quot;>
<INPUT Type=Hidden Name=sortBy Value=&quot;-1&quot;>
</FORM>

<SCRIPT Language=&quot;JavaScript&quot;>
function reSort( which )
{
    document.doSort.sortBy.value = which;
    document.doSort.submit( );
}
function popUp1(URL1) {
New1 = open(URL1 , &quot;New1&quot;, &quot;toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=295,height=230,screenX=50,screenY=50,left=50,top=50&quot;);
}
</SCRIPT>

<CENTER>
<FONT Size=&quot;+2&quot;>
Showing <% = (fileCount+1) %> files from directory <% = path %>
</FONT>
<P>
Click on a column heading to sort by that column. Click the same column
again to reverse the sort.
<P>
<TABLE Border=1 CellPadding=3>
<TR>
    <TH><A HREF=&quot;javascript:reSort(0);&quot;>File name</A></TH>
    <TH><A HREF=&quot;javascript:reSort(1);&quot;>Extension</A></TH>
    <TH><A HREF=&quot;javascript:reSort(2);&quot;>Type</A></TH>
    <TH><A HREF=&quot;javascript:reSort(3);&quot;>Size</A></TH>
    <TH><A HREF=&quot;javascript:reSort(4);&quot;>Created</A></TH>
    <TH><A HREF=&quot;javascript:reSort(5);&quot;>Last modified</A></TH>
    <TH><A HREF=&quot;javascript:reSort(6);&quot;>Last accessed</A></TH>
</TR>
<%
' With the array nicely sorted, this part is a piece of cake!
For i = 0 To fileCount
      Response.Write &quot;<TR>&quot; & vbNewLine
    For j = 0 To UBound( theFiles(i) )
      Response.Write &quot;    <TD>&quot;
      if j = 0 then
        Response.Write &quot;<div align='left'><a href='javascript:popUp1(&quot;&quot;&quot; & theFiles(i)(j) & &quot;&quot;&quot;);'>&quot;
        Response.Write &quot;<img src='&quot; & theFiles(i)(j) & &quot;' width='140' height='100' alt='Doc' border='0'></a></div>&quot;
        'Response.Write &quot;<A HREF='&quot; & theFiles(i)(j) & &quot;' TARGET=new>&quot;
      end if
      Response.Write theFiles(i)(j)
      if j = 0 then
        Response.Write &quot;</A>&quot;
      end if
      Response.Write &quot;</TD>&quot; & vbNewLine
    Next
    Response.Write &quot;</TR>&quot; & vbNewLine
Next
%>
</TABLE>


&quot;<a href=&quot;&quot;&quot;&objFile.Name&&quot;&quot;&quot;>&quot;
</BODY>
</HTML>
 
Thanks this is a start Im getting an error on this code
&quot;<a href=&quot;&quot;&quot;&objFile.Name&&quot;&quot;&quot;>&quot;
And the pics arnt showing up just the name of the pic, also the only field i want to show is the pic I dont need to show all the info about the pic.
I would like to show these 4 across and 10 down then move onto the next page.
Do you think you can help me with this or am I asking too much

Nick
 
okay, try this...
Code:
<%
' Change the DIRECTORY to point to any virtual directory of your choice.
CONST DIRECTORY = &quot;/img&quot; ' relative path in virtual directories

' Specify one of these constants for &quot;sortBy&quot;...
CONST FILE_NAME = 0
CONST FILE_EXT = 1
CONST FILE_TYPE = 2
CONST FILE_SIZE = 3
CONST FILE_CREATED = 4
CONST FILE_MODIFIED = 5
CONST FILE_ACCESSED = 6

' get requested sort order, if not first time here...
' (forward by name is default)
req = Request(&quot;sortBy&quot;)
If Len(req) < 1 Then sortBy = 0 Else sortBy = CInt(req)
req = Request(&quot;priorSort&quot;)
If Len(req) < 1 Then priorSort = -1 Else priorSort = CInt(req)

'
' did user ask for same sort? to reverse the order?
' but if so, then zap priorSort so clicking again will do forward!
If sortBy = priorSort Then
    reverse = true
    priorSort = -1
Else
    reverse = false
    priorSort = sortBy
End If

' now start the *real* code...
'
path = Server.MapPath( DIRECTORY )

Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set theCurrentFolder = fso.GetFolder( path )
Set curFiles = theCurrentFolder.Files
'
' And now a loop for the files
'
Dim theFiles( )
ReDim theFiles( 500 ) ' arbitrary size!
currentSlot = -1 ' start before first slot

' We collect all the info about each file and put it into one
' &quot;slot&quot; in our &quot;theFiles&quot; array.
'
For Each fileItem in curFiles
    fname = fileItem.Name
    fext = InStrRev( fname, &quot;.&quot; )
    If fext < 1 Then fext = &quot;&quot; Else fext = Mid(fname,fext+1)
    ftype = fileItem.Type
    fsize = fileItem.Size
    fcreate = fileItem.DateCreated
    fmod = fileItem.DateLastModified
    faccess = fileItem.DateLastAccessed
    currentSlot = currentSlot + 1
    If currentSlot > UBound( theFiles ) Then
        ReDim Preserve theFiles( currentSlot + 99 )
    End If
    ' note that what we put here is an array!
    theFiles(currentSlot) = Array(fname,fext,ftype,fsize,fcreate,fmod,faccess)
Next
'
' files are now in the array...
'
' As noted, it is actually an ARRAY *OF* ARRAYS. Which makes
' picking the column we will sort on easier!
'
' ...size and sort it...
fileCount = currentSlot ' actually, count is 1 more, since we start at 0
ReDim Preserve theFiles( currentSlot ) ' really not necessary...just neater!

' First, determine which &quot;kind&quot; of sort we are doing.
' (VarType=8 means &quot;string&quot;)
'
If VarType( theFiles( 0 )( sortBy ) ) = 8 Then
    If reverse Then kind = 1 Else kind = 2 ' sorting strings...
Else
    If reverse Then kind = 3 Else kind = 4 ' non-strings (numbers, dates)
End If

'
' A simple bubble sort for now...easier to follow the code...
'
For i = fileCount TO 0 Step -1
    minmax = theFiles( 0 )( sortBy )
    minmaxSlot = 0
    For j = 1 To i
        Select Case kind ' which kind of sort are we doing?
        ' after the &quot;is bigger/smaller&quot; test (as appropriate),
        ' mark will be true if we need to &quot;remember&quot; this slot...
        Case 1 ' string, reverse...we do case INsensitive!
            mark = (strComp( theFiles(j)(sortBy), minmax, vbTextCompare ) < 0)
        Case 2 ' string, forward...we do case INsensitive!
            mark = (strComp( theFiles(j)(sortBy), minmax, vbTextCompare ) > 0)
        Case 3 ' non-string, reverse ...
            mark = (theFiles( j )( sortBy ) < minmax)
        Case 4 ' non-string, forward ...
            mark = (theFiles( j )( sortBy ) > minmax)
        End Select
        ' so is the current slot bigger/smaller than the remembered one?
        If mark Then
            ' yep, so remember this one instead!
            minmax = theFiles( j )( sortBy )
            minmaxSlot = j
        End If
    Next
    ' is the last slot the min (or max), as it should be?
    If minmaxSlot <> i Then
        ' nope...so do the needed swap...
        temp = theFiles( minmaxSlot )
        theFiles( minmaxSlot ) = theFiles( i )
        theFiles( i ) = temp
    End If
Next
' Ta-da! The array is sorted!
'
%>
<FORM Name=&quot;doSort&quot; Method=&quot;Get&quot;>
<INPUT Type=Hidden Name=priorSort Value=&quot;<% = priorSort %>&quot;>
<INPUT Type=Hidden Name=sortBy Value=&quot;-1&quot;>
</FORM>

<SCRIPT Language=&quot;JavaScript&quot;>
function reSort( which )
{
    document.doSort.sortBy.value = which;
    document.doSort.submit( );
}
function popUp1(URL1) {
New1 = open(URL1 , &quot;New1&quot;, &quot;toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=295,height=230,screenX=50,screenY=50,left=50,top=50&quot;);
}
</SCRIPT>

<CENTER>
<FONT Size=&quot;+2&quot;>
Showing <% = (fileCount+1) %> files from directory <% = path %>
</FONT>
<TABLE Border=1 CellPadding=3>
<%
' With the array nicely sorted, this part is a piece of cake!
k = 1
a = 4  'number of images across
r = 10 'number of rows down
s = request(&quot;p-row&quot;)
if s = &quot;&quot; then
  s = 0  ' capture starting row from passed param when you call this page
end if
e = (s + (a * r)) - 1 'capture ending row from passed param when you call this page
if e > fileCount then
  e = fileCount
end if
response.write &quot;start &quot; & s & &quot; end &quot; & e
For i = s To e
    j = 0
    if k = 1 then
      Response.Write &quot;<TR>&quot; & vbNewLine
    end if
      Response.Write &quot;<TD>&quot;
        Response.Write &quot;<div align='left'><a href='javascript:popUp1(&quot;&quot;&quot; & theFiles(i)(j) & &quot;&quot;&quot;);'>&quot;
        Response.Write &quot;<img src='&quot; & theFiles(i)(j) & &quot;' width='140' height='100' alt='Doc' border='0'></a></div>&quot;
        Response.Write &quot;</A>&quot;
      Response.Write &quot;</TD>&quot; & vbNewLine
    if k = 4 then
      Response.Write &quot;</TR>&quot; & vbNewLine
    end if
    if k = 4 then
      k = 0
    end if
    k = k + 1
Next
e = e + 1
Response.Write &quot;<a href='test.asp?p-row=&quot; & e & &quot;'>Next &quot; & r & &quot;</a>&quot;
%>
</TABLE>


</BODY>
</HTML>
 
wow you are close they display 40 per page but when I click next it gives an error says page cannot be found.

Also on another note all the alt tags say DOC can we make the alt tag whatever the picture is called lets say test.jpg

Thanks
 
figured out the next page thing i needed to change the page to test4.asp you had it as test.

Just the alt tag now oh and one other thing when it displays the pics at some point my test4.asp shows up is there a way for it not to show asp pages in the table.
 
Replace test.asp with your page in:
Response.Write &quot;<a href='test.asp?p-row=&quot; & e & &quot;'>Next &quot; & r & &quot;</a>&quot;

To change the alt tag:
height='100' alt='&quot; & theFiles(i)(j) & &quot;' border

it would be easier to not have .asp pages in this directory...this page doesn't need to be there to work.

You can do this:
Code:
For i = s To e
    j = 0
    if theFiles(i)(1) = &quot;gif&quot; or _
       theFiles(i)(1) = &quot;jpg&quot; then
      if k = 1 then
        Response.Write &quot;<TR>&quot; & vbNewLine
      end if
        Response.Write &quot;<TD>&quot;
        Response.Write &quot;<div align='left'><a href='javascript:popUp1(&quot;&quot;&quot; & theFiles(i)(j) & &quot;&quot;&quot;);'>&quot;
        Response.Write &quot;<img src='&quot; & theFiles(i)(j) & &quot;' width='140' height='100' alt='&quot; & theFiles(i)(j) & &quot;' border='0'></a></div>&quot;
        Response.Write &quot;</A>&quot;
        Response.Write &quot;</TD>&quot; & vbNewLine
      if k = 4 then
        Response.Write &quot;</TR>&quot; & vbNewLine
      end if
      if k = 4 then
        k = 0
      end if
      k = k + 1
    end if
Next
but I don't have time to figure out how to make up for the blank space skipping the .asp page creates.

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top