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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help converting PHP script please

Status
Not open for further replies.

gibbo171

Programmer
Dec 13, 2007
33
GB
Can anyone help me convert the PHP code below to vbscript ( Or offer an alternative) please

I am trying to loop through all image files in a folder and then display them in a slide show

thanks

gibbo



//PHP SCRIPT: getimages.php
Header("content-type: application/x-javascript");

//This function gets the file names of all images in the current directory
//and ouputs them as a JavaScript array
function returnimages($dirname=".") {
$pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)"; //valid image extensions
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){ //if this file is a valid image
//Output it as a JavaScript array element
echo 'galleryarray['.$curimage.']="'.$file .'";';
$curimage++;
}
}

closedir($handle);
}
return($files);
}

echo 'var galleryarray=new Array();'; //Define array in JavaScript
returnimages() //Output the array elements containing the image file names

it links to the following on my intranet page


<script src="./pics/getimages.php"></script>

<script type="text/javascript">

var curimg=0
function rotateimages(){
document.getElementById("slideshow").setAttribute("src", "./pics/"+galleryarray[curimg])
curimg=(curimg<galleryarray.length-1)? curimg+1 : 0
}

window.onload=function(){
setInterval("rotateimages()", 2500)
}
</script>

<div style="width: 170px; height: 160px">
<img id="slideshow" src="./pics/pic01.jpg" />
</div>
 
[1]
[tt]
<%
'getimages.asp
response.contenttype="application/x-javascript"

function returnimages(dirname)
dim rx,curimage,fso,ofolder,ofile

set rx=new regexp
rx.pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)"

curimage=0;
set fso=server.createobject("scripting.filesystemobject")
set ofolder=fso.getfolder(dirname)
for each ofile in ofolder.files
if rx.test(ofile.name) then
'[blue]slight uncertainty on path here, check it out yourself[/blue]
response.write "galleryarray[" & curimage & "]=[blue]""./pic/""[/blue]" & ofile.name & """;" & vbcrlf
curimage=curimage+1
end if
next
set ofolder=nothing
set fso=nothing

end function

response.write "var galleryarray=new Array();" & vbcrlf
returnimages server.mappath(".")
%>
[/tt]
[2]
[tt] <script src="./pics/getimages.asp"></script>[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top