communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "image listing" - download "list image folder"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

image listing - list image folder was created/last modified on Fri 19 Mar 2004 6:31 PM

this snippet reads a given directory and returns an array of the images found. gets some information about the images as well .

drop this in any directory and replace the path to the folder with ./ and specify the files you want to show.
you get a list of all files which mach the criteria.
  
  <?php
  
  $imgdir
= '/Users/lixlpixel/Pictures/pics/'; // the directory, where your images are stored
  
$allowed_types = array('png','jpg','jpeg','gif'); // list of filetypes you want to show
  
  
$dimg = opendir($imgdir);
  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
   
  
for($x=0; $x < $totimg; $x++)
  {
   
$size = getimagesize($imgdir.'/'.$a_img[$x]);
  
   
// do whatever
   
$halfwidth = ceil($size[0]/2);
   
$halfheight = ceil($size[1]/2);
   echo
'name: '.$a_img[$x].' width: '.$size[0].' height: '.$size[1].'<br />';
  }
  
  
?>

learn more about some of the PHP functions used in this snippet: array, ceil, count, dir, echo, end, file, filetype, for, getimagesize, in_array, list, opendir, readdir, reset, return, sort, strtolower, substr, while

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari