Page 1 of 1

sorting a directory?

Posted: Mon Jul 14, 2003 8:59 am
by Dopetroep
Hey all,

I'm sorry for asking this question ('cause i have the idea it's an newbee question)
But i tried all kind of sorting and nothing seems to work.
Maybe one of you can help me? :roll:
I want to display images sorted by alphabet but they seem to be sorted by last saved date.

here is the code:

Code: Select all

<? 

// IvoDKA photo Script



// Configuration 



$woord="Foto"; // name of the php file

$path2 = "$gallery/thumbs"; // dir where the thumbnails are in

$path = "$gallery"; // dir where the photos are in

$title = "$gallery - Pagina ". ($page + 1); 

//translation pagina means page and foto means photo

// header, this is above the photos 

$header = "$gallery"; 



// Configuration 





$clm = "5"; // number of colloms

$rows = "4"; // number of rows

$t_w = "120"; 

$t_h = "90"; 



?> 



<style type="text/css">

<!--

@import url(../styleie.css);



body { background-color: rgb(80,80,80) }

body, p, td { color: rgb(180,180,180); font: 12px verdana, arial, sans-serif }



a:link, a:active, a:visited { color: wheat; text-decoration: none; font-size: 12px }

a:hover { text-decoration: underline }



/* heading size fixes for Netscape */

h1, h2, h3, h4, h5, h6 { text-align: center; font-weight: bold }

h1 { font-size: 150% }

h2 { font-size: 135% }

h3 { font-size: 125% }

-->

</style>

</head> 

<body bgcolor='#CCCCFF' leftmargin='0' topmargin='0'> 

<div align="center">

<? 

echo "<h1>$header</h1>"; 

echo "<br><br><center><b><b><h2>$title</h2></b></b><br><br>"; 

$min = (1+($page * 20)); 

$max = (($page +1) * 20); 

$number = $clm * $rows; 

$break = (($page * 20) + $clm); 

echo "<table border=0 cellpadding=0 cellspacing=0><tr>"; 

$d = dir("$path2"); 

$count = -1; 




while($entry=$d->read())
 { 

    if (($count >= $min) AND ($count <= $max)){ 


                

            if(eregi(".jpg|.jpeg|.gif|.bmp|.png", $entry)){ 

		ClearStatCache(); 

   $size = GetImageSize("$path/$entry"); 

                

                $size[0] = $size[0] + 20; 

                $size[1] = $size[1] + 25; 

                 
  $file_size=fileSize("$path/$entry"); 

                $file_size = round($file_size / 1000) . "k"; 

    

        

            echo ("<td><a href="#" onmouseover="window.status='Vergroten';return true;" 

            onmouseout="window.status=''; return true" 

            onclick="window.open('$path/$entry','pix$count','width=$size[0],height=$size[1],innerwidth=$size[0],innerheight=$size[1],directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no,top=0,left=0,leftmargin=0,topmargin=0,marginwidth=0,marginheight=0,screenX=0,screenY=0');return false"><img src='$path2/$entry'"); 

            echo " border=0 alt=$count ></a>&nbsp;&nbsp;&nbsp;<br>$entry<br><br>&nbsp;</td>\n"; // width=$t_w 

        

            } 

        

        if ($count == $break){ 

        echo "</tr>\n<tr>\n"; 

        $break = $count + $clm ; 

        } 

    } 



    $count++; 

} 



$d->close(); 

echo "</tr></table>"; 

$pages = ($count / 20); 

$pageplus = ($page + 1); 

$pagemin = ($page - 1); 

if (($page + 1) < $pages){ 

    $volgende = "  | <a href=$woord.php?gallery=$gallery&page=$pageplus>Volgende 20 Foto's</a> |"; 

} 
//volgende means next and vorige means last
//woord means word

if (($page+1) > "1"){ 

    $vorige = "| <a href=$woord.php?gallery=$gallery&page=$pagemin>Vorige 20 Foto's</a> |"; 

} 



// Footer, this is below the photos

echo "$vorige $volgende<br><br>Copyright 2002-2003 DopeTroep.NL<br>mochten er foto's tussen zitten die van u zijn <br>en u deze liever niet op deze pagina laat staan <br>kunt u contact op nemen met dope@dopetroep.nl"; 

//above is just some dutch comentary no script




?>
BTW this code is not writen by me...
Please can somebody help?

Posted: Mon Jul 14, 2003 11:53 am
by m3rajk
je ne sais pas beacoup français.
yo no hablo espanole
ich sprechen bisschen Duetsch und Yiddish

it will help (me at least) if the code and it's comments are in english, the only human language i can really claim to know (hey, i've tried those ones above, but i hae a language based learning disability... no short term memroy, and the way i developed to compensate result in rapind grammer/syntax aquisition... still, it doesn't help that i can't learn vocab lists.. thus growing up in the united states of america, all i really know for human languages are english)

as long as you don't need db interaction (comments on the pictures, though it wouldn't be hard to modify so it does that) i can give you a LONG file that you can put in a directory, and all the directories below it are sorted by picture type (jpg, gif, png, bmp are supported, i can modify it to support more) and alphabetically. it makes thumbs (in png format) of pngs and jpgs. but they have to actually be png/jpg, not just having the extention modified to be one

Posted: Mon Jul 14, 2003 12:15 pm
by Dopetroep
I tried to translate as much as possible i hope you can help me?

Thanks for trying anyways.

BTW I try to learn english but i'm not so good at it yet.. :(

Posted: Mon Jul 14, 2003 12:37 pm
by m3rajk
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>&nbsp;";
    }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>&nbsp;";
    }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>&nbsp;";
    }
  }
  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>&nbsp;";
    }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>&nbsp;";
    }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>&nbsp;";
    }
  }
  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";
}

?>