Viewing Image from directory HELP

images php coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
php-forum Fan User
php-forum Fan User
Posts: 622
Joined: Fri Aug 05, 2011 9:53 am

Re: Viewing Image from directory HELP

Post by NigelRen » Fri Aug 05, 2011 10:18 am

There are a couple of things you need to do ( I think )
First is to remove the / from the end of the directory name, I think this will allow it to pick up the directory properly. The second thing is to trap if the scandir has failed. Sacndir will return false if it hasn't worked for any reason so something like...

Code: Select all

$dirname = "directory-name";

$images = scandir($dirname);
if ( $images ) {
    $ignore = Array(".", "..");
    foreach($images as $curimg){
        if(!in_array($curimg, $ignore)) {
            echo "<img src='directory-name/$curimg' /><br/> 

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest