how to list all imags in a directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yhenew
    New Member
    • Aug 2012
    • 1

    #1

    how to list all imags in a directory

    i have tried to display all images from a directory. it works almost for all browser, but does not function in mozilla firefox latest version(14.0.1) .it only display the name of the image.the segment of code is the following.

    Code:
    <?php
    
    	// selecting a photo from folder	
      $gallary=$dnn['gallary_photo'];
      $dir ='../../images'. DIRECTORY_SEPARATOR .$gallary.DIRECTORY_SEPARATOR ;
        $imgs = array();
    
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                if (!is_dir($file) && preg_match("/\.(bmp|jpe?g|gif|png)$/", $file)) {
                    array_push($imgs, $file);
                }
            }
    
            closedir($dh);
        } else {
            die('cannot open ' . $dir);
        }
    
    $emgs = glob($dir."*.*");
    for ($i=0; $i<count($emgs); $i++)
    {
    	$num = $emgs[$i];
    	print $num."<br />"; // display full path of the image
    	echo '<img src="'.$num.'" alt="random image" />'."<br /><br />";
    }
    ?>
    please help me!!!!!
    Last edited by Dormilich; Aug 7 '12, 08:20 AM. Reason: Please use [CODE] [/CODE] tags when posting code.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you need to check, whether the image path is correct with respect to the browser context.

    It cannot be a PHP issue, because PHP is executed on the server.

    Comment

    Working...