954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP Image Gallery | Tutorial

Hello.
I'm going to show you how to make a basic php image gallery.
Firstly, create the following filesindex.php
view.php
/images (dir)
Now, for the code.
index.php

<?php
$img = array();
$img[] = array('title'=>'img1', 'src' = 'img1.jpg');
?>
<html>
<head>
<title>mygallery | homepage</title>
</head>
<body>
<h2>mygallery</h2>
<?php
for($i = 0;$i <= count($img);$i++;) {
echo '<div class="slide">';
echo '<a href="slide.php?id='.$img[$i]['src'].'&title='.$img[$i]['title'].'" target="_blank">';
echo '<span style="font-size:15pt">'.$img[$i]['title'].'</span><img src="images/'.$img[$i]['src'].'" width="100" height="100" />';
echo '</a>';
echo '</div>';
}
?>
</body>
</html>

slide.php

<html>
<head>
<title>mygallery : viewing <?php echo $_GET['title']; ?></title>
</head>
<body>
<h2><?php echo $_GET['title']; ?></h2>
<img src="images/<?php echo $_GET['src']; ?>" />
</body>
</html>
Matthew N.
Junior Poster
101 posts since Jul 2010
Reputation Points: 10
Solved Threads: 10
 

Sorry, view.php is meant to be slide.php

Matthew N.
Junior Poster
101 posts since Jul 2010
Reputation Points: 10
Solved Threads: 10
 

It would be more helpful to others, if you'd include some more information on how and why you do things, instead of just showing code.

It would also be helpful if the $img array is filled with all files from your images folder. You can do this easily with glob .

pritaeas
Posting Expert
Moderator
5,483 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Ok, I'll remember that for next time.

Matthew N.
Junior Poster
101 posts since Jul 2010
Reputation Points: 10
Solved Threads: 10
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: