Listing and previewing images in a directory using PHP -


i'm trying improve administrator panel of website. need preview images in thumbnails folder when i'm using thumbnails news dont have upload image second time. found great script, failed read directory error. here script:

<?php // filetypes display $imagetypes = array("image/jpeg", "image/gif", "image/png"); // original php code chirp internet: www.chirp.com.au // please acknowledge use of code including header. function getimages($dir) { global $imagetypes; // array hold return value $retval = array(); // add trailing slash if missing if(substr($dir, -1) != "/") $dir .= "/"; // full server path directory $fulldir = "{$_server['document_root']}/$dir"; $d = @dir($fulldir) or die("getimages: failed opening directory $dir reading"); while(false !== ($entry = $d->read())) { // skip hidden files if($entry[0] == ".") continue; // check image files $f = escapeshellarg("$fulldir$entry"); $mimetype = trim(`file -bi $f`); foreach($imagetypes $valid_type) { if(preg_match("@^{$valid_type}@", $mimetype)) { $retval[] = array( 'file' => "/$dir$entry", 'size' => getimagesize("$fulldir$entry") ); break; } } } $d->close(); return $retval; } // fetch image details $images = getimages("../images/thumbnails"); // display on page foreach($images $img) { echo "<div class=\"photo\">"; echo "<img src=\"{$img['file']}\" {$img['size'][3]} alt=\"\"><br>\n"; // display image file name link echo "<a href=\"{$img['file']}\">",basename($img['file']),"</a><br>\n"; // display image dimenstions echo "({$img['size'][0]} x {$img['size'][1]} pixels)<br>\n"; // display mime_type echo $img['size']['mime']; echo "</div>\n"; } ?> 

i appreciate if help..

edit:

<div style=" height: 200px; width: 600px; overflow: auto;"> <?php foreach(glob("../thumbnail/".'*') $filename){ echo "<div style=\"display:inline-table; font-size:10px; font-family:'tahoma'; margin:5px;\">"; echo "<img width=\"100px\" height=\"100px\" src=\"../thumbnail/$filename\"/>"; echo "<br>".basename($filename) . "<br>"; echo "</div>"; } ?> </div> 

this method works perfect. no need use complicated scripts. anyway, can please tell me how check images less 100px x 100px displayed?

<?php foreach(glob("../thumbnail/".'*') $filename){ list($width, $height, $type, $attr) = getimagesize("../thumbnail/".$filename); if($width>=100 || $height >=100) continue; $rest = substr($filename, 3); ?> 

that should it..


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -