Welcome Guest [Log In] [Register]
Welcome to Chibiwolf. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Simple Gallery Script - Php
Topic Started: Jun 18 2008, 01:31 AM (39 Views)
MusicUploader
Member Avatar
The Ownager
[ *  *  *  * ]
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. 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:

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://cdesigns.co.cc/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.

Code:
 

function images($cat){

// Let's specify our category
$directory = "http://cdesigns.co.cc/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:

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://cdesigns.co.cc/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://cdesigns.co.cc/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.
I Loved Her So Much I Saw A Chance And Missed It Now Im Broken

┏┫  | |   ┣┓  ┏┓ 
┗┫━━ ┃ ━━┣┛  ┣┫ 
 ┃ ━━━━━ ┃ ┏┳┫┣┳┓ 
 ┗━━┳━┳━━┛ ┃    ┃ 
━━━━┃ ┃    ┗━┳┳━┛
━━━━┃ ┗━━━━━━┛┃
Posted Image
Offline Profile Quote Post Goto Top
 
DarkCannon
Member Avatar
Willy Wolf
[ *  *  *  *  *  * ]
OMG! Chibi we need this on our site! A gallery!
[size=14]I AM A BUNNY! FEAR ME! I SHALL NIBBLE ON YOUR CARROTS! RAWR![/size]
Offline Profile Quote Post Goto Top
 
MusicUploader
Member Avatar
The Ownager
[ *  *  *  * ]
lol he could use if he wants lol
I Loved Her So Much I Saw A Chance And Missed It Now Im Broken

┏┫  | |   ┣┓  ┏┓ 
┗┫━━ ┃ ━━┣┛  ┣┫ 
 ┃ ━━━━━ ┃ ┏┳┫┣┳┓ 
 ┗━━┳━┳━━┛ ┃    ┃ 
━━━━┃ ┃    ┗━┳┳━┛
━━━━┃ ┗━━━━━━┛┃
Posted Image
Offline Profile Quote Post Goto Top
 
Chibi
Member Avatar
Shmell mah finger
Admins
Were would it go? Footer?
Posted Image

"I'd kill the Jews." -glare- "I'd not kill the Jews, no. I'd toss in a penny and watch them fight to the death. -snickering- I did the same with two Catholic priests but I tossed in a small boy!! And the winner, had to fight Michael Jackson!"%mh%-100%mh%
Offline Profile Quote Post Goto Top
 
DarkCannon
Member Avatar
Willy Wolf
[ *  *  *  *  *  * ]
Most likely above <% BOARD %>
[size=14]I AM A BUNNY! FEAR ME! I SHALL NIBBLE ON YOUR CARROTS! RAWR![/size]
Offline Profile Quote Post Goto Top
 
Chibi
Member Avatar
Shmell mah finger
Admins
But you never used IF DC >>

How would you know?
Posted Image

"I'd kill the Jews." -glare- "I'd not kill the Jews, no. I'd toss in a penny and watch them fight to the death. -snickering- I did the same with two Catholic priests but I tossed in a small boy!! And the winner, had to fight Michael Jackson!"%mh%-100%mh%
Offline Profile Quote Post Goto Top
 
« Previous Topic · Computer Talk · Next Topic »
Add Reply