ok. this is in 3 files on my hd. i know i put them into one somewhere.. just so a friend would be able to use it and have one file to deal with... don't feel liek doing that again.. so here's 3 files that i think do what you want when used together
index.php
Code: Select all
<?php
$what=$_GET['what'];
if (isset($what)){
if($what=='welcome'){
welcome();
}elseif($what=='gallist'){
gallist();
}elseif($what=='filler'){
filler();
}
}else{
main();
}
function main(){
?><html>
<head>
<title>welcome to Gallery</title>
<meta name="author" content="Joshua Perlmutter">
<meta name="use" content="use only with consent of author. modify only with consent of author.">
<meta name="purpose" content="the purpose of this php script is to turn a section of webspace into picture galleries. it's initial form only works with jpeg encoded file ending with .jpg other file types may have been added by the time you read this. check with the author. this is one of three php pages used to create the galleries">
<meta name="contact" content="to contact the author, e-mail me at Archimedes5739@hotmail.com">
</head><frameset rows="20%,*">
<?php
echo "<frame src="$_SERVER[PHP_SELF]?what=welcome" noresize scrolling="auto">\n\t\t";
echo "<frameset cols="20%,*">\n\t\t\t";
echo "<frame src="$_SERVER[PHP_SELF]?what=gallist" noresize scrolling="auto">\n\t\t\t";
echo "<frame src="$_SERVER[PHP_SELF]?what=filler" noresize scrolling="auto" name="display">\n\t\t";
echo "</frameset>\n\t</frameset>\n</html>";
}
function welcome(){ // should be a short write up on how to use
?>
<html>
<body bgcolor="#0000" text="#ffffff">
<center><p>To view picture from our various functions, just click the link on the left frame. The pictures will appear as a 100 by 100 thumbnail. Just click a thumbnail for the full sized in a new window.</p></center>
</body>
</html>
<?php
}
function gallist(){ // should be a list of subdirectories
?><html><head>
<meta name="function" content="this is the gallery listing frame. it should be left as a frame.">
</head><body bgcolor="#000000" text="#ffffff" link="#FF00FF" alink="#00FFFF" vlink="#FF0000"><center>
<p>the galleries are...<br>
<?php
// get directories
$dirs=array(); // empty directory array
$d=opendir(getcwd()) or die($php_errormsg);
while(false !==($f=readdir($d))){
if(is_dir($f)){
if(!(($f=='.')||($f=='..'))){ // we don't need this directory or the parent directory
$dirs[]=$f;
}
}
}
sort($dirs);
// iterate though the list of directories making links calling gallery.php?dir=$dir
foreach($dirs as $dir){
echo "<a href="gallery.php?dir=$dir/" target="display">$dir</a>\n<br>";
}
echo "</body></html>";
}
function filler(){ // inital display where the pics belong
echo "<html><body bgcolor="#000000" text="#ffffff"><p>the images will appear here</p></body></html>\n";
}
?>
gallery.php
Code: Select all
<?php
/* this takes a directory and finds all the *.jpg and *.jpe and *.jpeg and *.png files and then creates a set of thumbs that link to the full picture.
this also works with gifs, but uses html constraints for gifs. if you add gif support to your gd, the gif section is functional and the lines here on gif should be switched to <img src="createthumb.php?pic=$image&type=gif" border="0"> from <img src="$image" border="0" height="250" width="250">
without that, changing the thumb size requires editing those two lines here fo height and width are the same as in the createthumb.php file. */
## set the directory
$dir = $_GET['dir']; $page=$_GET['page']; $disp=$_GET['disp'];
## set number to display per page (if not user defined)
if(!(isset($disp))){ $disp=25; }
## get the contents
$jpgs=array(); $pngs=array(); $gifs=array();
$d=opendir($dir) or die($php_errormsg);
while(false !==($f=readdir($d))){
$here=getcwd(); $pospics=$here . '/' . $dir . $f;
if(is_file($pospics)){
if((preg_match('/\.jpg$/', $f))||(preg_match('/\.jpe$/', $f))||(preg_match('/\.jpeg$/', $f))){
$jpgs[] = $f;
}elseif(preg_match('/\.png$/', $f)){
$pngs[] = $f;
}elseif(preg_match('/\.gif$/', $f)){
$gifs[] = $f;
}
}
}
sort($jpgs); sort($pngs); sort($gifs);
## make the header
?><html><head>
<meta name="author" content="Joshua Perlmutter">
<meta name="source generation" content="This page created via a php script. If you would like to use it, contact the author: Archimedes5739@hotmail.com">
<meta name="use" content="Do not use without permission. This is meant to be a frame for an index page that creates galleries">
</head>
<body bgcolor="#000000" text="#FFFFFF"><p>Click on any thumbnail to bring up the full picture in a new window.</p><hr><p>
<?php
## find out how many pictures there are
$numjpgs=count($jpgs); $numpngs=count($pngs); $numgifs=count($gifs);
$size=$numjpgs+$numpngs+$numgifs;
if(isset($page)){
## iterate through contents making the thumbs links.
$stop=$page*$disp;
$start=$stop-$disp;
for($i=$start;$i<$stop;$i++){
if($i<$numjpgs){ ## if there's another jpeg to display
$image=$dir . $jpgs[$i];
list($iw, $ih)=getimagesize($image); $iw+=20; $ih+=32;
echo "<a name="#$image" href="#$image" onClick="window.open('$image', '_blank', 'height=$ih,width=$iw,scrollbars=yes,resizable=yes');"><img src="createthumb.php?pic=$image&type=jpg" border="0"></a> ";
}elseif(($numjpgs<=$i)&&($i<($numjpgs+$numpngs))){ ## if there's another png to display
$j=$i-$numjpgs;
$image=$dir . $pngs[$j];
list($iw, $ih)=getimagesize($image); $iw+=20; $ih+=32;
echo "<a name="#$image" href="#$image" onClick="window.open('$image', '_blank', 'height=$ih,width=$iw,scrollbars=yes,resizable=yes');"><img src="createthumb.php?pic=$image&type=png" border="0"></a> ";
}elseif((($numjpgs+$numpngs)<=$i)&&($i<$size)){ ## if there's another gif to display
$j=$i-($numjpgs+$numpngs);
$image=$dir . $gifs[$j];
list($iw, $ih)=getimagesize($image); $iw+=20; $ih+=32;
echo "<a name="#$image" href="#$image" onClick="window.open('$image', '_blank', 'height=$ih,width=$iw,scrollbars=yes,resizable=yes');"><img src="$image" border="0" height="250" width="250"></a> ";
}
}
echo "</p><hr><p>";
## make the page links
echo "Go to page: <a href=$_SERVER[PHP_SELF]?dir=$dir&page=1>1</a>";
$k=2;
while($size>$disp){
echo " <a href=$_SERVER[PHP_SELF]?dir=$dir&page=$k>$k</a>";
$k++;
$size-=$disp; ## reduce by amt displayed
}
echo "</p></body></html>";
}else{
## iterate through contents making the thumbs links.
for($i=0;$i<$disp;$i++){
if($i<$numjpgs){ ## if there's another jpeg to display
$image=$dir . $jpgs[$i];
list($iw, $ih)=getimagesize($image); $iw+=20; $ih+=32;
echo "<a name="#$image" href="#$image" onClick="window.open('$image', '_blank', 'height=$ih,width=$iw');"><img src="createthumb.php?pic=$image&type=jpg" border="0"></a> ";
}elseif(($numjpgs<=$i)&&($i<($numjpgs+$numpngs))){ ## if there's another png to display
$j=$i-$numjpgs;
$image=$dir . $pngs[$j];
list($iw, $ih)=getimagesize($image); $iw+=20; $ih+=32;
echo "<a name="#$image" href="#$image" onClick="window.open('$image', '_blank', 'height=$ih,width=$iw');"><img src="createthumb.php?pic=$image&type=png" border="0"></a> ";
}elseif((($numjpgs+$numpngs)<=$i)&&($i<$size)){ ## if there's another gif to display
$j=$i-($numjpgs+$numpngs);
list($iw, $ih)=getimagesize($image); $iw+=20; $ih+=32;
$image=$dir . $gifs[$j];
echo "<a name="#$image" href="#$image" onClick="window.open('$image', '_blank', 'height=$ih,width=$iw');"><img src="$image" border="0" height="250" width="250"></a> ";
}
}
echo "</p><hr><p>";
if($size>$disp){ ## let the user see the pages, if needed
echo "Go to page: <a href=$_SERVER[PHP_SELF]?dir=$dir&page=1>1</a>";
$k=2;
while($size>$disp){
echo " <a href=$_SERVER[PHP_SELF]?dir=$dir&page=$k>$k</a>";
$k++;
$size-=$disp; ## reduce by amt displayed
}
}
echo "</p></body></html>";
}
?>
createthumb.php
Code: Select all
et($pic)){
if(isset($type)){
if($type=='jpg'){
// make the thumb
$src=ImageCreateFromJPEG($pic);
$width=ImageSx($src); $height=ImageSy($src);
$x=$hght; $y=$wdth; $dst=ImageCreate($x,$y);
ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height);
header('Content-Type: image/png'); ImagePNG($dst);
}elseif($type=='png'){
// make the thumb
$src=ImageCreateFromPNG($pic);
$width=ImageSx($src); $height=ImageSy($src);
$x=$hght; $y=$wdth; $dst=ImageCreate($x,$y);
ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height);
header('Content-Type: image/png'); ImagePNG($dst);
}elseif($type=='gif'){
// make the thumb
$src=ImageCreateFromGIF($pic);
$width=ImageSx($src); $height=ImageSy($src);
$x=$hght; $y=$wdth; $dst=ImageCreate($x,$y);
ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height);
header('Content-Type: image/png'); ImagePNG($dst);
}else{
echo "could not determine type";
}
}else{
echo "there is no type";
}
}else{
echo "there is no pic";
}
?>