| | |
Urgent requirement of image gallery in php
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hi Friends,
Good news, I have modified the script somewhat more.now it supports
1. moving in directory ans subdirectories.
2. moving up the directory
3. slide show of the images.
just edit the following code and replace the "images" with the directory you want your photo album to start with.
Cheers.
Good news, I have modified the script somewhat more.now it supports
1. moving in directory ans subdirectories.
2. moving up the directory
3. slide show of the images.
just edit the following code and replace the "images" with the directory you want your photo album to start with.
PHP Syntax (Toggle Plain Text)
if($curr_dir == "") { $curr_dir = 'images'; }
Cheers.
Vivek Rawat
Keep solving complexities.
Keep solving complexities.
okk friends use this code this is just modified and runnig fantastically.......
<style>
td{font: 12px Arial; color: #333333;}
</style>
<script language=javascript>
function clicked(val)
{
location.href = "rec_dir_list.php?dir="+val;
}
</script>
<html>
<title>Foto Album</title>
<body>
<?php
//level variable will hold 1 or 0, depending on if the directory has only files.
//1 - if sub-folders are still there
//0 - if only image files are there.
function list_images($imgdir,$level)
{
$imgdir = 'images/'; // the directory, where your images are stored
$allowed_types = array('png','jpg','jpeg','gif'); // list of filetypes you want to show
$dimg = opendir($imgdir);
$imgfile = readdir($dimg);
while($imgfile = readdir($dimg))
{
if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))
{
$a_img[] = $imgfile;
sort($a_img);
reset ($a_img);
}
}
$totimg = count($a_img); // total image number
if($totimg > 0)
{
echo '<center><table><tr>';
for($x=0; $x < $totimg; $x++)
{
$size = getimagesize($imgdir.'/'.$a_img[$x]);
$halfwidth = ceil($size[0]/4);
$halfheight = ceil($size[1]/4);
if($x % 4 == 0 && $x != 0)
{
echo '</tr><tr>';
}
echo '<td><table border=1><tr><td><img src="'.$imgdir.'/'.$a_img[$x].'" width='.$halfwidth.' height='.$halfheight.'></td></tr></table></td>';
if($level==1)
{
break;
}
}
if($totimg%4 == 0)
{
echo '</table>';
}
else
{
echo '</tr></table>';
}
}
else
{
echo '<center><table><tr><td>No Images found</td></tr></table>';
}
}
function recur_dir($dir)
{
$flag=0;$ind=1;
$dirlist = opendir($dir);
echo '<center><table bgcolor=#eeeeee width="30%"><tr>';
while ($file = readdir ($dirlist))
{
if ($file != '.' && $file != '..')
{
$newpath = $dir.'/'.$file;
$level = explode('/',$newpath);
if (is_dir($newpath))
{
$ind += 1;
$flag = 1;
echo "<td>";
echo '<center><table><tr><td>';
list_images($dir.'/'.end($level),1);
echo '</td></tr><tr><td align=center>';
echo '<a href=javascript<b></b>:clicked("'.$dir.'/'.end($level).'")>'.end($level).'</a>';
echo '</td></tr></table>';
echo "</td>";
}
}
}
if($flag==0)
{
echo "<td>";
list_images($dir,0);
echo "</td></tr><tr><td><hr>Current Dir: ". $dir;
echo "</td></tr></table>";
}
else
{
echo "</tr><tr><td colspan=".$ind." align=center><hr>Current Dir: ". $dir;
echo "</td></tr></table>";
}
closedir($dirlist);
}
$curr_dir = $_REQUEST['dir'];
if($curr_dir == "")
{
$curr_dir = './images';
}
recur_dir($curr_dir);
?>
</body>
</html>
but you people must create a folder 'images' exactly where you keep this page with some images..
<style>
td{font: 12px Arial; color: #333333;}
</style>
<script language=javascript>
function clicked(val)
{
location.href = "rec_dir_list.php?dir="+val;
}
</script>
<html>
<title>Foto Album</title>
<body>
<?php
//level variable will hold 1 or 0, depending on if the directory has only files.
//1 - if sub-folders are still there
//0 - if only image files are there.
function list_images($imgdir,$level)
{
$imgdir = 'images/'; // the directory, where your images are stored
$allowed_types = array('png','jpg','jpeg','gif'); // list of filetypes you want to show
$dimg = opendir($imgdir);
$imgfile = readdir($dimg);
while($imgfile = readdir($dimg))
{
if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))
{
$a_img[] = $imgfile;
sort($a_img);
reset ($a_img);
}
}
$totimg = count($a_img); // total image number
if($totimg > 0)
{
echo '<center><table><tr>';
for($x=0; $x < $totimg; $x++)
{
$size = getimagesize($imgdir.'/'.$a_img[$x]);
$halfwidth = ceil($size[0]/4);
$halfheight = ceil($size[1]/4);
if($x % 4 == 0 && $x != 0)
{
echo '</tr><tr>';
}
echo '<td><table border=1><tr><td><img src="'.$imgdir.'/'.$a_img[$x].'" width='.$halfwidth.' height='.$halfheight.'></td></tr></table></td>';
if($level==1)
{
break;
}
}
if($totimg%4 == 0)
{
echo '</table>';
}
else
{
echo '</tr></table>';
}
}
else
{
echo '<center><table><tr><td>No Images found</td></tr></table>';
}
}
function recur_dir($dir)
{
$flag=0;$ind=1;
$dirlist = opendir($dir);
echo '<center><table bgcolor=#eeeeee width="30%"><tr>';
while ($file = readdir ($dirlist))
{
if ($file != '.' && $file != '..')
{
$newpath = $dir.'/'.$file;
$level = explode('/',$newpath);
if (is_dir($newpath))
{
$ind += 1;
$flag = 1;
echo "<td>";
echo '<center><table><tr><td>';
list_images($dir.'/'.end($level),1);
echo '</td></tr><tr><td align=center>';
echo '<a href=javascript<b></b>:clicked("'.$dir.'/'.end($level).'")>'.end($level).'</a>';
echo '</td></tr></table>';
echo "</td>";
}
}
}
if($flag==0)
{
echo "<td>";
list_images($dir,0);
echo "</td></tr><tr><td><hr>Current Dir: ". $dir;
echo "</td></tr></table>";
}
else
{
echo "</tr><tr><td colspan=".$ind." align=center><hr>Current Dir: ". $dir;
echo "</td></tr></table>";
}
closedir($dirlist);
}
$curr_dir = $_REQUEST['dir'];
if($curr_dir == "")
{
$curr_dir = './images';
}
recur_dir($curr_dir);
?>
</body>
</html>
but you people must create a folder 'images' exactly where you keep this page with some images..
Last edited by nil_gh_80; Jul 11th, 2008 at 7:15 am.
Hi Nil,
Can you please let me know, what modificatio you have made.
I think you uncommented the following line
if yes, then this will make this code to work in only one level.
I have made this script to work in more then one levels.
Can you please let me know, what modificatio you have made.
I think you uncommented the following line
PHP Syntax (Toggle Plain Text)
$imgdir = 'images/'; // the directory, where your images are stored
if yes, then this will make this code to work in only one level.
I have made this script to work in more then one levels.
Vivek Rawat
Keep solving complexities.
Keep solving complexities.
![]() |
Other Threads in the PHP Forum
- Previous Thread: Looking For A Partner
- Next Thread: ERROR: supplied argument is not a valid MySQL result resource
| Thread Tools | Search this Thread |
advanced apache api array beginner binary broken cakephp check checkbox class cms code cookies cron curl database date datepart display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google head href htaccess html if...loop image include includingmysecondfileinthechain insert ip javascript job joomla jquery key library limit link login mail menu mlm multiple mysql oop password paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search server sessions smarty sms sorting source space sql startup stored syntax system table traffic tutorial unicode update upload url validator variable video web youtube zend






