dudetheman
10-30-2003, 02:40 PM
I am trying to read jpg's from a directory into an array and choose a random image from that array and display it. Here is my code:
<br>PHP</br>
myPix = new Array("images/01.jpg","images/08.jpg","images/13.jpg","images/40.jpg")
imgCt = myPix.length
fso = new ActiveXObject("Scripting.FileSystemObject")
folderObj = fso.GetFolder("F:/Helpdesk/images")
folderObj = new Folder("F:/Helpdesk/images")
fileObjs = folderObj.Files
iCt = fileObjs.Count
alert(iCt)
//imgCt = fileObjs.Count
//myPix = fileObjs[randomNum].path
function choosePic() {
if (document.images) {
randomNum = Math.floor((Math.random() * imgCt));
document.myPicture.src = myPix[randomNum]
}
}
<br>PHP</br>
myPix = new Array("images/01.jpg","images/08.jpg","images/13.jpg","images/40.jpg")
imgCt = myPix.length
fso = new ActiveXObject("Scripting.FileSystemObject")
folderObj = fso.GetFolder("F:/Helpdesk/images")
folderObj = new Folder("F:/Helpdesk/images")
fileObjs = folderObj.Files
iCt = fileObjs.Count
alert(iCt)
//imgCt = fileObjs.Count
//myPix = fileObjs[randomNum].path
function choosePic() {
if (document.images) {
randomNum = Math.floor((Math.random() * imgCt));
document.myPicture.src = myPix[randomNum]
}
}