Thread: Simple gallery
View Single Post
  #1 (permalink)  
Old 05-14-2007, 01:09 PM
Jaan's Avatar   
Jaan Jaan is offline
Mod
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 884
Last Blog:
Wadio Media Layout Com...
Credits: 56
Rep Power: 15
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Simple gallery

Hey ya.. i was thinking that i havent submitted any tutorials so.. i must do it now..well today i'm going to show you how you can create your own gallery ^^.. Okay let's start.

Well first, i'm going to create one folder called images and set it's CHMOD to 777. Then i'll make a index file into it because i don't want that some quests are browsing this folder. This index file can be blank or you can use my tutorial where i teach you how to protect your files with one little script Check. Now let's go back to our main directory and let's start with our gallery script. If you want to create a category, then just make a folder into your /images/ folder and name it to "nature" (for example).

Now let's make our category list and let's show how much files are in those categories:

PHP Code:
// Let's get our category name
$cat $_GET['cat'];

function 
categories(){

// Specify your directory were are your categories
$dir opendir("images");

// Now let's get our categories
while (($file readdir($dir)) !== false){

// Let's remove . and .. and index file if there is index file
if($file == "."){
echo 
"";
}elseif(
$file == ".."){
echo 
"";
}elseif(
$file == "index.php"){
echo 
"";
}else{

// Here we are going to find out how much files are in our category
$directory "http://forum.codecall.net/images/$file";
$filecount 0;
$d dir($directory); 
while (
$f $d->read()) { 
 if((
$f!= ".") && ($f!= "..")) { 
 if(!
is_dir($f)) 
 
$filecount++; 
 } 
}
$filecount;

// Display your categories and how much files are in those categories
echo "<a href='index.php?cat=$file'>$file($filecount)</a><br>";
}
}
closedir($dir);


Now we can see all our categories and how many files are in those categories. Now we should make a function what will display our images what are in those categories.

PHP Code:
function images($cat){

// Let's specify our category
$directory "http://forum.codecall.net/images/$cat/";

// If there is not this category what user have entered let's display an error
if(!is_dir($directory)){
die(
"<center><b><font>The category don't exist!</font></b></center>");
}

// Now if everything is okay let's display our images
$dir opendir($directory);
while ((
$file readdir($dir)) == true){

// Let's remove unwanted records like . , .. and index file if there is one
if($file == "."){
echo 
"";
}elseif(
$file == ".."){
echo 
"";
}elseif(
$file == "index.php"){
echo 
"";
}else{

// Show our images what are in our specified category
$url $file;
echo 
"<br>";
echo 
"<a href='images/$cat/$url'><img src='images/$cat/" $file "' border='0' width='135' height='125'></a>";
echo 
"<br><br>";
}
}
closedir($dir);


Now your simple gallery is done. Here is our full script:

PHP Code:
<?php

// Let's get our category name
$cat $_GET['cat'];

function 
categories(){

// Specify your directory were are your categories
$dir opendir("images");

// Now let's get our categories
while (($file readdir($dir)) !== false){

// Let's remove . and .. and index file if there is index file
if($file == "."){
echo 
"";
}elseif(
$file == ".."){
echo 
"";
}elseif(
$file == "index.php"){
echo 
"";
}else{

// Here we are going to find out how much files are in our category
$directory "http://forum.codecall.net/images/$file";
$filecount 0;
$d dir($directory); 
while (
$f $d->read()) { 
 if((
$f!= ".") && ($f!= "..")) { 
 if(!
is_dir($f)) 
 
$filecount++; 
 } 
}
$filecount;

// Display your categories and how much files are in those categories
echo "<a href='index.php?cat=$file'>$file($filecount)</a><br>";
}
}
closedir($dir);

}

function 
images($cat){

// Let's specify our category
$directory "http://forum.codecall.net/images/$cat/";

// If there is not this category what user have entered let's display an error
if(!is_dir($directory)){
die(
"<center><b><font>The category don't exist!</font></b></center>");
}

// Now if everything is okay let's display our images
$dir opendir($directory);
while ((
$file readdir($dir)) == true){

// Let's remove unwanted records like . , .. and index file if there is one
if($file == "."){
echo 
"";
}elseif(
$file == ".."){
echo 
"";
}elseif(
$file == "index.php"){
echo 
"";
}else{

// Show our images what are in our specified category
$url $file;
echo 
"<br>";
echo 
"<a href='images/$cat/$url'><img src='images/$cat/" $file "' border='0' width='135' height='125'></a>";
echo 
"<br><br>";
}
}
closedir($dir);

}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
FONT{
font-size:12px;
font-family: Arial, Helvetica, sans-serif;
}
.title{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:20px;
font-style: oblique;
}
.cattitle{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:15px;
color: #FFFFFF;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>My Gallery</title>
</head>
<body>

<table width="100%" border="1">
<tr>
<td>
<table width="100%" border="1">
<tr>
<td bgcolor="#6699FF"><br><center><font color="#FFFFFF" class="title">My Gallery</font></center><br></td>
</tr>
<tr>
<td bgcolor="#0033FF"><font class="cattitle"><b>Categories</b></font></td>
</tr>
<tr>
<td><?php categories(); ?></td>
</tr>
<tr>
<td>
<center>
<table border="0" width="80%">
<tr>
<td>
<?php images($cat); ?>
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>
</td>
</tr>
</table>

</body>
</html>
I hope it helped. Enjoy.

Regards,
Jaan
__________________


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| Need help? Send a
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Last edited by Jaan; 10-06-2007 at 07:33 AM.
Reply With Quote

Sponsored Links