Click to See Complete Forum and Search --> : Photo gallery


akadis
03-08-2004, 12:44 AM
i was trying to create a photo gallery using this (http://hotwired.lycos.com/webmonkey/01/27/index3a.html?tw=programming) guide and i get this (http://www.literside.net/main/gallery/index.php)

I obviously don't want the lines of code appearing on the page....and how do i get the rest to work?

the code for the page:
<html>
<head>
<title>Lite-rSide Photo Gallery</title>
<script language="javascript">
<!--
function photo_open(link, width, height)
{
var photoWindow = window.open(link,"photo",
'toolbar=0,location=0,directories=0,status=0,
menubar=0,scrollbars=0,resizable=0,width=
'+width+',height='+height);
}
//-->
</script>

<body bgcolor="#FFFFFF" text="#000000"
link="#00CCFF" alink="#00CCFF" vlink="#00CCFF">

<table cellpadding="2" align="center"
cellspacing="2" width="80%" border="0" align="center">
<?PHP
//initialize variables
$data_file = "list.photos";
$thumbnail_dir = "thumbs/";
$num_rows = 4;
$photos_per_row = 5;
$photos = file($data_file);
$total_photos = sizeof($photos);
$photos_per_page = $num_rows * $photos_per_row;
//check to see if the start variable exists in the URL.
//If not, then the user is on the first page - set start to 0
if(!isSet($start)){
$start = 0;
}
//init i to where it needs to start in the photos array
$i = $start;
$prev_start = $start - $photos_per_page;
$next_start = $start + $photos_per_page;
for ($row=0; $row < $num_rows; $row++){
print("<tr>\n");
for ($col=0; $col < $photos_per_row; $col++){
if($i < $total_photos){
$thumbnail = $thumbnail_dir.trim($photos[$i]);
$thumb_image_size = getimagesize($thumbnail);
$image_size = getimagesize(trim($photos[$i]));
print("<td align=\"center\"><
a href=\"javascript:photo_open('photo_display.php?photo=
".trim($photos[$i])."','".$image_size[0]."','
".$image_size[1]."');\"><img src=\"".$thumbnail.
"\" ".$thumb_image_size[3]."></a></td>\n");
} else {
print("<td></td>\n");
}
$i++;
}
print("</tr>\n");
}

//end table
?>
</table>

<div align="center">
<?PHP
//print out navigation links
if(($start == 0) && ($next_start < $total_photos)){

//you're at the beginning of the photo gallery

?>
<font face="arial, helvetica" size="2">
<b><a href="view.php?start=<
?PHP print($next_start):?>">next page</a>
<font color="#FF0000">»</font></b>
</font>
<?PHP
}
elseif (($start > 0) && ($next_start < $total_photos)){

//you're in the middle of the photo gallery

?>
<font face="arial, helvetica" size="2">
<b><font color="#FF0000">«
</font> <a href=\"view.php?start=
<?PHP print($prev_start); ?>">prev page</a></b></font>
<b>|</b>
<font face="arial, helvetica" size="2">
<b><a href="view.php?start=<
?PHP print($next_start); ?>">next page</a> <font
color="#FF0000">»</font></b></font>
<?PHP
}
elseif(($start == 0) && ($next_start > $total_photos)){

//you're in a photo gallery with only one page of photos

?>

<?PHP
}
else {

//you're at the end of the photo galley

?>
<font face="arial, helvetica" size="2">
<b><font color="#FF0000">«</font>
<a href="view.php?start=<?PHP print($prev_start); ?>
">prev page</a></b></font>
<?PHP
}
?>
</div>
</body>
</html>

the code for photo_display.php:
<head>
<title><?PHP print($photo);?></title>
</head>

<?PHP
$photo_size = getimagesize("$photo");
?>
<body bgcolor="#FFFFFF" marginheight="0"
marginwidth="0" leftmargin="0" topmargin="0"
rightmargin="0">

<img src="<?PHP print($photo);
?>" <?PHP print($photo_size[3]);
?> name="photo">

</body>
</html>

can anyone help me?
is there is a better way to make a photo gallery with php? - if so how??

Sam
03-08-2004, 01:13 AM
Originally posted by akadis

<
a href=\"javascript:photo_open('photo_display.php?photo=
".trim($photos[$i])."','".$image_size[0]."','
".$image_size[1]."');\"><img src=\"".$thumbnail.
"\" ".$thumb_image_size[3]."></a>

this segment is your problem, here's a rewritten version that should help:

<a href=\"java script: photo_open('photo_display.php?photo=
".trim($photos[$i])."','".$image_size[0]."','".$image_size[1]."');\"><img src=\"".$thumbnail."\"".$thumb_image_size[3]."></a>

make sure you squeeze that all into one line in your php file

akadis
03-08-2004, 05:24 PM
samij586 thanks for your help but it still isn't working... :confused: can anyone help me?
the gallery (http://www.literside.net/main/gallery/index.php) as it looks right now

jereece
03-08-2004, 05:32 PM
The absolute easiest way I know to create an online photo album is by using JAlbum (http://www.datadosen.se/jalbum/). It's easy, fast, free and customizable. You can edit the templates to suit your need. Here's a link to my album of funny photos made with JAlbum: http://www.jreece.com/FunnyFotos/. It's a simple example, but I like simple.

Michel_v_Duijse
03-10-2004, 06:59 AM
print("<td align=\"center\"><
a href=\"javascript<img src="images/smilies/tongue.gif" border="0" alt="">hoto_open('photo_display.php?photo=
".trim($photos[$i])."','".$image_size[0]."','
".$image_size[1]."');\"><img src=\"".$thumbnail.
"\" ".$thumb_image_size[3]."></a></td>\n");


Hi,

if i counted correct, this is the part of your code the parse error occurs.

You're using the print statment, like this:

print ("your text")

But you also want to print " (dubble quotes) in that statement.
You have to tell PHP which quotes are the begin and endquotes of your print statment, and which are the quotes you want to print.
To do that, you must escape the quotes you want to print.
You can do that by adding a backslash before the quotes.

You did it right with this part:
align=\"center\">

But not with this:
<img src="images/smilies/tongue.gif"


Besides, this part:
javascript<img src="images/smilies/tongue.gif" border="0" alt="">hoto_open

lookes weird. i think that something went wrong there, please check your original code.