Page 1 of 1

Photo Script Problems

Posted: Tue Jan 20, 2004 2:12 pm
by maboroshi
Hi everyone:

I have a photo gallery script that when you click on a thumbnail it goes to a PHP or HTML Page that displays the photo in a larger version there is only one problem I am having with that I can't do a write up of each photo because all the photos are on the same page this is for an art site I would like to be able to sell the print and I need a write up specific to that photo can anyone help to make it so when you click on a thumbnail it goes to a seperate page this is the code for the gallery

Code: Select all

<?php 
  $a = 0; 
  $new_tr = 0; 
  $filepath = "thumbnails"; 
  $url_path = "images2"; 
  $dir = dir($filepath); 
  $start=0; 
  $stop=22; 

if(!empty($_GET&#1111;'start']) && !empty($_GET&#1111;'stop'])) &#123; 
   $start=intval($_GET&#1111;'start']); 
   $stop=intval($_GET&#1111;'stop']); 
&#125; 

  echo "<table width="450" border="0" cellpadding="5" cellspacing="5">"; 

  while($entry=$dir->read()) &#123; 
   if($a>=$start && $a<$stop) &#123; // $a<$stop because from 0-19 you have 20 pictures 
      if($entry != "." && $entry != "..") &#123; 

           if (!($new_tr%5)) &#123;echo "<tr>";&#125; 
?>
  <td align="center" valign="top"> 
  <a href="waterpics.php?image=<?php echo urlencode($entry); ?>"> 
 
  <img src="<?php echo "$filepath/$entry"; ?>" alt="<?php echo $entry; ?>" border="1" class="imgborder"></a> 
  </td> 
  
<?php 
  $new_tr++; 
if (!($new_tr%5) && $new_tr!=0) &#123; echo "</tr>"; &#125; 

  &#125; // end of  if($entry 
&#125; // end of  if($new_tr>= 
$a++; 
&#125; // end of while 
?>

</tr><td width="450" align="center">
</table>

<?php 

if($start>=20) &#123; 
    $start2=$start-20; 
  echo "<a href="".$PHP_SELF."?start=".$start2."&stop=".$start."">previous | </a>"; 
&#125; 
echo " "; 
$stop2=$stop+20; 
echo "<a href="".$PHP_SELF."?start=".$stop."&stop=".$stop2.""> next </a>";
?>

and this is the code that displays the image on a new page

Code: Select all

<?php 

   $url_path      = "images2"; 

?>


<div align="center">

<img src="<?php echo "$url_path/" . $_GET&#1111;'image']; ?>" border="1" class="imgborder"><br>
<br>
 

<a href="javascript: history.back()">Back to where you where last</a>

</div>

Thanks to all those wonderfull PHP programmers who have helped me so far

Posted: Tue Jan 20, 2004 3:05 pm
by DuFF
Hmmm, since you're not using a database you will probably have to use text files or hardcode the descriptions into the website. What I would do is probably create a text file with the same name as the picture. Then in the page that shows the larger picture just do something like this:

Code: Select all

<?php

   $url_path = "images2";
   $filenamelength = strlen($_GET['image']) - 4;  //find the length of the image name
   $textfile = substr($_GET['image'], 0, $filenamelength);  //subtract the last 4 characters, for example: ".gif"
   $textfile .= ".txt"; // add ".txt" to the end of the image name
   $handle = fopen($url_path . "/" . $textfile, "r");  //open the text file
   $contents = fread($handle, filesize($textfile));  //get contents
   fclose($handle); //close the handle

?>


<div align="center">

<img src="<?php echo "$url_path/" . $_GET['image']; ?>" border="1" class="imgborder"><br>
<br>
<?php echo $contents ?>
<br><br>

<a href="javascript: history.back()">Back to where you where last</a>

</div>
So if you had the picture, myimage.gif, you would create a text file named myimage.txt. This hasn't been tested but I'm pretty sure it should work.

Still Need Help

Posted: Tue Jan 20, 2004 3:52 pm
by maboroshi
Hi I get this error when I ran your script I tried messing around with it a bit

but I am pretty sure its in the right directory it should be in the images2 directory am I correct


Warning: filesize(): Stat failed for 1blossoming.txt (errno=2 - No such file or directory) in S:\public_WWW\Web Sites\Almost Finished\waterpics.php on line


Thanks in advance

Cheers

Hey I figured it out

Posted: Tue Jan 20, 2004 4:18 pm
by maboroshi
Hey Never Mind I figured it out

Thanks

Cheers