hoeyjope
11-17-2006, 02:36 PM
alright i am getting frustrated with this code. I am using this javascript slideshow and can't seem to get it to work when i put it into my php page. The amount of images changes often so i need to load them dynamically. Here is my code, if there is a better way to do this let me know.
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ricocheting (ricocheting@hotmail.com) -->
<!-- Web Site: http://www.ricocheting.com -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin slideshow code
var rotate_delay = 5000; // delay in milliseconds (5000 = 5 secs)
current = 0;
function next() {
if (document.slideform.slide[current+1]) {
document.images.show.src = document.slideform.slide[current+1].value;
document.slideform.slide.selectedIndex = ++current;
}
else first();
}
function previous() {
if (current-1 >= 0) {
document.images.show.src = document.slideform.slide[current-1].value;
document.slideform.slide.selectedIndex = --current;
}
else last();
}
function first() {
current = 0;
document.images.show.src = document.slideform.slide[0].value;
document.slideform.slide.selectedIndex = 0;
}
function last() {
current = document.slideform.slide.length-1;
document.images.show.src = document.slideform.slide[current].value;
document.slideform.slide.selectedIndex = current;
}
function ap(text) {
document.slideform.slidebutton.value = (text == "Stop") ? "Start" : "Stop";
rotate();
}
function change() {
current = document.slideform.slide.selectedIndex;
document.images.show.src = document.slideform.slide[current].value;
}
function rotate() {
if (document.slideform.slidebutton.value == "Stop") {
current = (current == document.slideform.slide.length-1) ? 0 : current+1;
document.images.show.src = document.slideform.slide[current].value;
document.slideform.slide.selectedIndex = current;
window.setTimeout("rotate()", rotate_delay);
}
}
// End -->
</script>
</HEAD>
<BODY>
<?php
$myDirectory = opendir("../../../../myurl");
// get each entry
while($entryName = readdir($myDirectory)) {
//str_replace("img_","",$entryName);
$dirArray[] = $entryName;
}
// close directory
closedir($myDirectory);
// count elements in array
$indexCount = count($dirArray);
for($index=0; $index < $indexCount; $index++) {
$fileArray = str_replace("img_","",$dirArray);
$numArray = str_replace(".png","",$fileArray);
}
// sort 'em
sort($numArray);
// remove first two elements
$finalArray = array_slice($numArray, 2);
// print 'em
print("<TABLE width=632 align=center border=1 cellpadding=5 cellspacing=0 class=whitelinks><tr>\n");
print("<td>");
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
if (substr("$numArray[$index]", 0, 1) != "."){ // don't list hidden files
print("<a target=show id=\"$numArray[$index]\" href=\"http://myurl/img_". "$numArray[$index]" .".png\">$numArray[$index] </a>| ");
}
}
print("<a target=show href=\"list_files3.php\">Index</a></td></tr></TABLE>\n");
print("<center><form name=slideform><table cellspacing=1 cellpadding=4 bgcolor=\"#000000\"><tr><td align=center bgcolor=\"white\"><b>Image Slideshow</b></td></tr><tr>
<td align=center bgcolor=\"white\" width=200 height=150>
<img src=\"http://myurl/img_0.png\" name=\"show\"></td>
</tr><tr><td align=center bgcolor=\"#C0C0C0\"><select name=\"slide\" onChange=\"change();\"><option value=\"http://myurl/img_". "$finalArray[$index]" ."png\" selected>$finalArray[0]");
for($index=1; $index < $indexCount; $index++) {
print("<option value=\"http://myurl/img_". "$finalArray[$index]" ."png\">$finalArray[$index]");
}
print("</select></td></tr><tr><td align=center bgcolor=\"#C0C0C0\"><input type=button onClick=\"first();\" value=\"|<<\" title=\"Beginning\"><input type=button onClick=\"previous();\" value=\"<<\" title=\"Previous\"><input type=button name=\"slidebutton\" onClick=\"ap(this.value);\" value=\"Start\" title=\"AutoPlay\"><input type=button onClick=\"next();\" value=\">>\" title=\"Next\"><input type=button onClick=\"last();\" value=\">>|\" title=\"End\"></td></tr></table></form></center>");
?>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ricocheting (ricocheting@hotmail.com) -->
<!-- Web Site: http://www.ricocheting.com -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin slideshow code
var rotate_delay = 5000; // delay in milliseconds (5000 = 5 secs)
current = 0;
function next() {
if (document.slideform.slide[current+1]) {
document.images.show.src = document.slideform.slide[current+1].value;
document.slideform.slide.selectedIndex = ++current;
}
else first();
}
function previous() {
if (current-1 >= 0) {
document.images.show.src = document.slideform.slide[current-1].value;
document.slideform.slide.selectedIndex = --current;
}
else last();
}
function first() {
current = 0;
document.images.show.src = document.slideform.slide[0].value;
document.slideform.slide.selectedIndex = 0;
}
function last() {
current = document.slideform.slide.length-1;
document.images.show.src = document.slideform.slide[current].value;
document.slideform.slide.selectedIndex = current;
}
function ap(text) {
document.slideform.slidebutton.value = (text == "Stop") ? "Start" : "Stop";
rotate();
}
function change() {
current = document.slideform.slide.selectedIndex;
document.images.show.src = document.slideform.slide[current].value;
}
function rotate() {
if (document.slideform.slidebutton.value == "Stop") {
current = (current == document.slideform.slide.length-1) ? 0 : current+1;
document.images.show.src = document.slideform.slide[current].value;
document.slideform.slide.selectedIndex = current;
window.setTimeout("rotate()", rotate_delay);
}
}
// End -->
</script>
</HEAD>
<BODY>
<?php
$myDirectory = opendir("../../../../myurl");
// get each entry
while($entryName = readdir($myDirectory)) {
//str_replace("img_","",$entryName);
$dirArray[] = $entryName;
}
// close directory
closedir($myDirectory);
// count elements in array
$indexCount = count($dirArray);
for($index=0; $index < $indexCount; $index++) {
$fileArray = str_replace("img_","",$dirArray);
$numArray = str_replace(".png","",$fileArray);
}
// sort 'em
sort($numArray);
// remove first two elements
$finalArray = array_slice($numArray, 2);
// print 'em
print("<TABLE width=632 align=center border=1 cellpadding=5 cellspacing=0 class=whitelinks><tr>\n");
print("<td>");
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
if (substr("$numArray[$index]", 0, 1) != "."){ // don't list hidden files
print("<a target=show id=\"$numArray[$index]\" href=\"http://myurl/img_". "$numArray[$index]" .".png\">$numArray[$index] </a>| ");
}
}
print("<a target=show href=\"list_files3.php\">Index</a></td></tr></TABLE>\n");
print("<center><form name=slideform><table cellspacing=1 cellpadding=4 bgcolor=\"#000000\"><tr><td align=center bgcolor=\"white\"><b>Image Slideshow</b></td></tr><tr>
<td align=center bgcolor=\"white\" width=200 height=150>
<img src=\"http://myurl/img_0.png\" name=\"show\"></td>
</tr><tr><td align=center bgcolor=\"#C0C0C0\"><select name=\"slide\" onChange=\"change();\"><option value=\"http://myurl/img_". "$finalArray[$index]" ."png\" selected>$finalArray[0]");
for($index=1; $index < $indexCount; $index++) {
print("<option value=\"http://myurl/img_". "$finalArray[$index]" ."png\">$finalArray[$index]");
}
print("</select></td></tr><tr><td align=center bgcolor=\"#C0C0C0\"><input type=button onClick=\"first();\" value=\"|<<\" title=\"Beginning\"><input type=button onClick=\"previous();\" value=\"<<\" title=\"Previous\"><input type=button name=\"slidebutton\" onClick=\"ap(this.value);\" value=\"Start\" title=\"AutoPlay\"><input type=button onClick=\"next();\" value=\">>\" title=\"Next\"><input type=button onClick=\"last();\" value=\">>|\" title=\"End\"></td></tr></table></form></center>");
?>