Using Include...my pics disappear when trying to view them

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php_beginner_83
Forum Newbie
Posts: 6
Joined: Wed Apr 29, 2009 11:05 am

Using Include...my pics disappear when trying to view them

Post by php_beginner_83 »

Hi All

Can anyone help me with this..please.
I'm still pretty new to PHP and am slowly figuring it out.
I have a photo gallery, that you can navigate through the pics to view each one using 'Next' and 'Previous' links. I want to include this in a website I'm creating. On the website's main page I have a menu. On the menu is the option to select 'Photos'. When you select this, the file that creates the photo gallery is included. However, when I click the 'Next' link to move through the photos, it disappears.
Can anyone explain to me why this happens and how I can fix it.

Thanks much.

My website code is....

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="sclMenu.js"></script>
 
<style type="text/css">
// css styles here
</style>
 
</head>
 
<body bgcolor="#000000">
 
<div id="header">
<img src="Banner_USA.jpg" alt="header image">
</div>
 
<div id="menuNav" >
 
<ul id="dd">
<li><a href="#" class="menu" id="mmenu1" 
      onmouseover="mopen(1);"
      onmouseout="mclosetime();">Home</a>
    <div class="submenu" id="menu1"
      onmouseover="mcancelclosetime()"
      onmouseout="mclosetime();">        <a href="menu_2.php?page=main">Sights</a>
        <a href="menu_2.php?page=photo">Photos</a>
        <a href="#">Test 3</a>
        <a href="#">Test 4</a>
    </div>
  </li>
  <li><a href="#" class="menu" id="mmenu2" onmouseover="mopen(2);" onmouseout="mclosetime();">New York</a>
    <div class="submenu" id="menu2" onmouseover="mcancelclosetime()" onmouseout="mclosetime();">
  
    </div>
  </li>
  <li><a href="#" class="menu">Memphis</a></li>
  <li><a href="#" class="menu">Nashville</a></li>
  <li><a href="#" class="menu" id="mmenu3" onmouseover="mopen(3);" onmouseout="mclosetime();">San Francisco</a>
    <div class="submenu" id="menu3" onmouseover="mcancelclosetime()" onmouseout="mclosetime();">
        <a href="#">Office</a>
        <a href="#">Sales</a>
        <a href="#">Customer Service</a>
        <a href="#">Shipping</a>
    </div>
  </li>
</ul>
 
</div>
 
<div id="content">
 
<?php
// you build an array for the pages you have. 
$index = array( "main" => "Sights_text.php" , "photo" => "My_Try_At_Album.php" ); 
 
if ( !empty( $_GET["page"] ) ) { 
   $page = $_GET["page"]; 
 
    if ( array_key_exists( $page , $index ) ) 
        include( $index[$page] ); 
} 
 
?> 
 
</div>
 
</body>
</html>
And the code for my photo gallery is...


Code: Select all

<?php
// directory where photos are kept
$directory = 'images/thumbnails/';
$photos = array();
 
if($handle = opendir($directory))
{
    while(false !== ($file = readdir($handle)))
    {
        if ($file != "." && $file != ".." ) 
        {
            $photos[] = $file;
        }
    }
    closedir($handle);
}
 
$imgIndex = $_GET['img'];
 
if(!isset($photos[$imgIndex]))
{
    $imgIndex = 0;
}
 
$currentImage = $photos[$imgIndex];
 
if ($imgIndex<=0)
{
    $prev = "Previous";
}
else
{
    $prev = "<a href=\"".$_SERVER[PHP_SELF]."?img=".($imgIndex-1)."\">Previous</a>";
}
 
if ($imgIndex>=(count($photos)-1))
{
    $next = "Next";
}
else
{
    $next = "<a href=\"".$_SERVER[PHP_SELF]."?img=".($imgIndex+1)."\">Next</a>";
}
 
?>
<html>
<body>
<?php
 
echo "$prev $next<br>";
echo "<img src=\"{$directory}/{$currentImage}\">";
 
?>
</body>
</html>
Last edited by Benjamin on Wed Apr 29, 2009 12:06 pm, edited 1 time in total.
Reason: Changed code type from text to php.
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: Using Include...my pics disappear when trying to view them

Post by mattpointblank »

It might not be the source of your problem, but it doesn't help that in the file you're including, you have another set of <html> and </html> tags (and <body> and </body> too) - you don't need these as the file is included on a page that already has them.
php_beginner_83
Forum Newbie
Posts: 6
Joined: Wed Apr 29, 2009 11:05 am

Re: Using Include...my pics disappear when trying to view them

Post by php_beginner_83 »

Thanks for the suggestion :-)

I just tried it and still have the problem :-(
php_beginner_83
Forum Newbie
Posts: 6
Joined: Wed Apr 29, 2009 11:05 am

Re: Using Include...my pics disappear when trying to view them

Post by php_beginner_83 »

Thanks McInfo...that did the trick!

Another lesson learned...thanks again :-)
Post Reply