PDA

View Full Version : PHP Photo Album script



SWest
12-29-2005, 05:22 AM
I'm trying to implement this script, but I'm having some difficulty.

I have followed the directions and double checked the work...I'm getting an error in FrontPage saying that I have a syntax error on line 2 which is the first <head> line below. I'm also getting 2 errors saying galleryarray isn't defined.

Any help?

SWest

<html>
<head>
<title>selfserv.gif</title>


</script>


<style type="text/css">

.slideshow{ /*CSS for DIV containing each image*/
float: left;
margin-right: 10px;
margin-bottom: 10px;
}

.slideshow img{ /*CSS for each image tag*/
border: 0px none;
width: 200px;
height: 106px
}

#navlinks{ /*CSS for DIV containing the navigational links*/
width: 400px;
}

#navlinks a{ /*CSS for each navigational link*/
margin-right: 8px;
margin-bottom: 3px;
font-size: 110%;
}

#navlinks a.current{ /*CSS for currently selected navigational link*/
background-color: yellow;
}
</style>

</head>

jscheuer1
12-29-2005, 07:57 AM
This is the galleryarray from the demo:


//Specify images:
//galleryarray[x]=["path_to_image", "optional_title_attribute", "optional_text_description", "optional_link"]
var galleryarray=new Array()
galleryarray[0]=["photo1.jpg", "optional title", "optional description", "optional url"]
galleryarray[1]=["photo2.jpg", "optional title", "optional description", "optional url"]
galleryarray[2]=["photo3.jpg", "optional title", "optional description", "optional url"]
galleryarray[3]=["photo4.jpg", "optional title", "optional description", "optional url"]
galleryarray[4]=["photo5.jpg", "optional title", "optional description", "optional url"]
galleryarray[5]=["photo6.jpg", "optional title", "optional description", "optional url"]
galleryarray[6]=["photo7.jpg", "optional title", "optional description", "optional url"]

If you are getting an error that it is not defined, something is wrong with your syntax or you have left it out altogether. There could also be other problems. To be more specific, I would need to see your page:

.

elliott
12-29-2005, 05:43 PM
</script>


<style type="text/css">


There is a </script> there which appears to be sitting all alone... is this the problem?

As jscheuer1 says without a page it very difficult to see what is going on.

jstgermain
12-29-2005, 06:36 PM
There is a </script> there which appears to be sitting all alone... is this the problem?



remove the </script>...it should not be there. also, make sure to add the following code in after the <body> tag and make sure alle the images are named properly.



<script type="text/javascript">

/***********************************************
* Photo Album script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
***********************************************/

var dimension="3x2" //Specify dimension of gallery (number of images shown), such as 4x2, 3x1 etc

//Specify images:
//galleryarray[x]=["path_to_image", "optional_title_attribute", "optional_text_description", "optional_link"]
var galleryarray=new Array()
galleryarray[0]=["photo1.jpg", "optional title", "optional description", "optional url"]
galleryarray[1]=["photo2.jpg", "optional title", "optional description", "optional url"]
galleryarray[2]=["photo3.jpg", "optional title", "optional description", "optional url"]
galleryarray[3]=["photo4.jpg", "optional title", "optional description", "optional url"]
galleryarray[4]=["photo5.jpg", "optional title", "optional description", "optional url"]
galleryarray[5]=["photo6.jpg", "optional title", "optional description", "optional url"]
galleryarray[6]=["photo7.jpg", "optional title", "optional description", "optional url"]

var href_target="_new" //Enter target attribute of links, if applicable

var totalslots=dimension.split("x")[0]*dimension.split("x")[1]

function buildimage(i){
var tempcontainer=galleryarray[i][3]!=""? '<a href="'+galleryarray[i][3]+'" target="'+href_target+'">' : ""
tempcontainer+='<img src="'+galleryarray[i][0]+'" border="1" title="'+galleryarray[i][1]+'">'
tempcontainer=galleryarray[i][3]!=""? tempcontainer+'</a>' : tempcontainer
tempcontainer=galleryarray[i][2]!=""? tempcontainer+'<br \/>'+galleryarray[i][2] : tempcontainer
return tempcontainer
}

function jumptopage(p){
var startpoint=(p-1)*totalslots
var y=1;
for (i=0; i<totalslots; i++){
document.getElementById("slide"+i).innerHTML=(typeof galleryarray[startpoint+i]!="undefined")? buildimage(startpoint+i) : ""
}
while(document.getElementById("navlink"+y)!=null){
document.getElementById("navlink"+y).className=""
y++
}
document.getElementById("navlink"+p).className="current"
}

var curimage=0
for (y=0; y<dimension.split("x")[1]; y++){
for (x=0; x<dimension.split("x")[0]; x++){
if (curimage<galleryarray.length)
document.write('<div id="slide'+curimage+'" class="slideshow">'+buildimage(curimage)+'</div>')
curimage++
}
document.write('<br style="clear: left" />')
}

</script>

<!--Below HTML code refers to the navigational links for the gallery-->
<div id="navlinks">
<script type="text/javascript">
for (i=1; i<Math.ceil(galleryarray.length/totalslots)+1; i++)
document.write('<a id="navlink'+i+'" href="javascript:jumptopage('+i+')\">Page'+i+'</a> ')
document.getElementById("navlink1").className="current"
</script>
</div>

mhbackpacker
01-29-2007, 05:20 PM
I was experiencing the same problem with the 'galleryarray' I changed the php script from:

...................................................................................................
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY><PRE>&lt;?
Header("content-type: application/x-javascript");

function returnimages($dirname=".") {
$pattern="\.(jpg|jpeg|png|gif|bmp)$";
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){
$filedate=date ("M d, Y H:i:s", filemtime($file));
echo 'galleryarray[' . $curimage .']=["' . $file . '", "'.$filedate.'"];' . "\n";
$curimage++;
}
}

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

echo "var galleryarray=new Array();" . "\n";
returnimages();
?&gt;
</PRE></BODY></HTML>

...........................................................................................

to:

...........................................................................................

<?
Header("content-type: application/x-javascript");

function returnimages($dirname=".") {
$pattern="\.(jpg|jpeg|png|gif|bmp)$";
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){
$filedate=date ("M d, Y H:i:s", filemtime($file));
echo 'galleryarray[' . $curimage .']=["' . $file . '", "'.$filedate.'"];' . "\n";
$curimage++;
}
}

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

echo "var galleryarray=new Array();" . "\n";
returnimages();
?>

...................................................................................................

and it worked.

jscheuer1
01-29-2007, 05:45 PM
That's just a matter of the code getting mangled somewhere along the way as:

<PRE>&lt;?

was never in the distribution.