Jnerocorp Posted November 26, 2009 Share Posted November 26, 2009 Hello, is it possible for a php file to check a directory lets say for example called "images" to check the folder and only display the images in directory and not any files other than images. The image filetypes that are in the directory are: .bmp, .gif, .ico, .jpg, .png, .tiff Help appreciated -John Link to comment https://forums.phpfreaks.com/topic/183045-help-to-display-images-in-a-directory/ Share on other sites More sharing options...
Cosizzle Posted November 26, 2009 Share Posted November 26, 2009 John, check out this function http://ca2.php.net/opendir edit: quickly wrote a script based off the site <?php // The folder you want to look in $dir = "images/"; // check if the directory exists if (is_dir($dir)) { // open that directory if ($dh = opendir($dir)) { // while there are files within the folder while (($file = readdir($dh)) !== false) { echo "name".$file; // show their name echo "<br>"; // break } } } ?> Also look into http://ca2.php.net/explode and http://ca2.php.net/manual/en/function.implode.php Link to comment https://forums.phpfreaks.com/topic/183045-help-to-display-images-in-a-directory/#findComment-966043 Share on other sites More sharing options...
Jnerocorp Posted November 26, 2009 Author Share Posted November 26, 2009 thanks thats a nice funtion is it possible to use that to check for multiple filetypes and get the create the direct links to those filetypes that can be put like this: <?php echo '<a href="' . $imageurl . '"><img src="' . $imageurl . '" height="100" width="100"></a>'; ?> Link to comment https://forums.phpfreaks.com/topic/183045-help-to-display-images-in-a-directory/#findComment-966048 Share on other sites More sharing options...
Cosizzle Posted November 26, 2009 Share Posted November 26, 2009 A while back a wrote a class that should be what you're after http://cnicollonline.com/?p=209 You can download it at the bottom of that page. Link to comment https://forums.phpfreaks.com/topic/183045-help-to-display-images-in-a-directory/#findComment-966094 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.