Jump to content

help to display images in a directory


Jnerocorp

Recommended Posts

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

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

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>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.