deth4uall Posted March 8, 2010 Share Posted March 8, 2010 I am trying to create a script I can show in the list of directories and images in the folder that I am in. The supported types I am trying to only show are "image/jpg", "image/png" & "directory." I found this script but I am confused about how to implement it, I would like to have it as a index.php which would show the images and directory listings. # image types to display $imagetypes = array("image/jpeg", "image/gif"); # Original PHP code by Chirp Internet: www.chirp.com.au # Please acknowledge use of this code by including this header. function getImages($dir) { global $imagetypes; # array to hold return value $retval = array(); # add trailing slash if missing if(substr($dir, -1) != "/") $dir .= "/"; # full server path to directory $fulldir = "{$_SERVER['DOCUMENT_ROOT']}/$dir"; $d = @dir($fulldir) or die("getImages: Failed opening directory $dir for reading"); while(false !== ($entry = $d->read())) { # skip hidden files if($entry[0] == ".") continue; # check for image files if(in_array(mime_content_type("$fulldir$entry"), $imagetypes)) { $retval[] = array( "file" => "/$dir$entry", "size" => getimagesize("$fulldir$entry") ); } elseif (is_dir($entry)) { $dirval[] = $entry; } } $d->close(); return $retval; } # display on page foreach($images as $img) { echo "<div class=\"photo\">"; echo "<img src=\"{$img['file']}\" {$img['size'][3]} alt=\"\"><br>\n"; echo "<a href=\"{$img['file']}\">",basename($img['file']),"</a><br>\n"; echo "({$img['size'][0]}x{$img['size'][1]})"; echo "</div>\n"; } Link to comment https://forums.phpfreaks.com/topic/194552-showing-images-and-directories/ Share on other sites More sharing options...
deth4uall Posted March 8, 2010 Author Share Posted March 8, 2010 Any ideas on how I can either change it or do this from scratch? lol... Link to comment https://forums.phpfreaks.com/topic/194552-showing-images-and-directories/#findComment-1023262 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.