Jump to content

photo album in php


Jf88

Recommended Posts

Hi,

 

I am a complete beginner in PHP. Now I want to make a photo album for my website. I currently have made an index.php with 3 includes to other php pages:

 

toonalbums.php (translation: showalbums.php)

This page I use to make an list of all the photo albums that are available in a directory of my choice. The code in this page also needs to generate hyperlinks so I can watch all the photo's inside the specific albums.

 

toonalbuminhoud.php (translation: showalbumcontent.php)

This page I use so all the photo's will be visible in thumbnails. The thumbnails need to be hyperlinks so a bigger version of the photo's can be seen.

 

toonfoto.php (translation: showfoto.php)

This page I use to show the foto in his original size.

 

The code I currently use is:

 

toonalbums.php

<?php
$mapnaam = 'albums/';

echo '<ul>';
if ($handle = opendir($mapnaam))
{
while (false !== ($albumnaam = readdir($handle)))
{		
	echo '<li><a href="?album=' . $_GET['album'] . '"></a></li>';
}
closedir($handle);
}
echo '</ul>';

?>

 

toonalbuminhoud.php:

<?php
if(isset($_GET['album']))
{
	$albumnaam = $_GET['album'];
	$mapnaam = 'albums/' . $albumnaam;

	echo '<ul>' ;	
	if ($handle = opendir($albumnaam))
	{
		while (false !== ($fotonaam = readdir($handle)))
		{
			echo '<li><a href="?album=' . $_GET['album'] . '$foto=' . $_GET['foto']  . '">
				<img class="thumbnail" src="' . $mapnaam . '/' . $fotonaam . '" alt="' . $fotonaam . '"/>
			</a></li>';
		}
		closedir($handle);
	}
	echo '</ul>';
}
?>

 

toonfoto.php:

<?php
if(isset($_GET['foto']))
{
	$fotonaam = $_GET['foto'];
	$mapnaam = 'albums/' . $_GET['album'];

	echo '<img src="' . $mapnaam . '/' . $fotonaam . '" alt="' . $fotonaam . '"/>';
}
?>

 

the following page is the index with the 3 includes:

<body>
<div id="albums">
    	<?php include 'toonalbums.php'; ?>
    </div>
    <div id="albuminhoud">
    	<?php include 'toonalbuminhoud.php'; ?>
    </div>
    <div id="foto">
    	<?php include 'toonfoto.php'; ?>
    </div>    
</body>

 

When I execute the index I get the following error:

"Notice: Undefined index: album in C:\wamp\www\webprogramming\php2\toonalbums.php on line 9"

 

I don't know exactly what's wrong but I think it has something to do with the variables and the '$_GET['album']' code I use in the echo on the 'toonalbum.php' page. Also the map album exists and there are a couple of maps with photo's inside.

 

I hope someone can help me and explain how I can fix the code, because I think I am pretty close to getting it to work.

 

 

 

Link to comment
Share on other sites

Does album already exist in the url?  I would do something like:

 

if (isset($_GET['album'])) {

$album = $_GET['album'];

} else {

$album = 0; //Whatever default value you want if an album isn't selected

}

 

Then change to:

 

echo '<li><a href="?album=' . $album . '"></a></li>';

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.