Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: A How To: Random album image with ASP  (Read 4617 times)

0 Members and 1 Guest are viewing this topic.

John

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 75
A How To: Random album image with ASP
« on: October 20, 2003, 02:01:32 am »

snip..... old code. see below
Logged

John

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 75
A How To: Random album image with ASP
« Reply #1 on: October 20, 2003, 02:38:19 am »

do we even need index.html file in the pic paths, its a blank file yes?
Logged

John

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 75
A How To: Random album image with ASP
« Reply #2 on: October 20, 2003, 02:51:53 am »

Revised. Here is the ASP code that will display all images in a path, if anyone wants it i can modify to resize the pic on the fly instead of set it to 100x100 but it suits my needs .

in head:

Code: [Select]
<%

' Initialize the random number generator. love asp randomize :) .
Randomize

Dim intImageNumber ' A var to store our randomn number

' Set our random images pickup directory.
Const IMGS_DIR = "./coppermine/albums/userpics/YOUR_GALLERY/"

' Variables for our FileSystemObject objects
Dim objFSO, objFolderObject, objFileCollection, objFile

' A pair of integers for our random image selection
Dim intFileNumberToUse, intFileLooper

' A "handle" to the file we choose to use
Dim objImageFileToUse

' A variable to build our image tag
Dim strImageSrcText

' Lets see what's in the directory:
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolderObject = objFSO.GetFolder(Server.MapPath(IMGS_DIR))
Set objFSO = Nothing

Set objFileCollection = objFolderObject.Files
Set objFolderObject = Nothing

' Get a count of files and use it to generate a random
' number from 1 to the count.
intFileNumberToUse = Int(objFileCollection.Count * Rnd) + 1

' Set up loop control so we exit when we get to the random
' file number we just picked.
intFileLooper = 1
For Each objFile in objFileCollection
        If intFileLooper = intFileNumberToUse Then
                ' Get a "handle" on the appropriate file
                Set objImageFileToUse = objFile
                Exit For
        End If
        intFileLooper = intFileLooper + 1
Next

Set objFileCollection = Nothing

' Build our img src tag text
strImageSrcText = IMGS_DIR & objImageFileToUse.Name

Set objImageFileToUse = Nothing
%>


in body wherever:

Code: [Select]
<img src= "<%= strImageSrcText %>" width ="100" height="100" alt= "Random Gallery Image"/>

John
Logged
Pages: [1]   Go Up
 

Page created in 0.017 seconds with 18 queries.