Jump to content

Display all images in a directory..


forumnz

Recommended Posts

Thanks.. I have come up with this but it wont display the image. What is wrong with it?

 

<?php
$d = dir("upload/sport_motocross");
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
   echo "<a img src=" . $entry."\n" . "/>";
}
$d->close();
?> 

Link to comment
Share on other sites

<?php
$d = dir("upload/sport_motocross");
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
   if ($entry == "." || $entry == "..") {
       continue;
   }elseif (!ereg('gif|jpg|jpeg|png', $entry)) {
       continue;
   }  
   echo "<img src=" . $entry."\n" . "/>";
}
$d->close();
?> 

 

Try that.

Link to comment
Share on other sites

I find it's much easier to use the glob() function.

 

<?php
fioreach(glob({'upload/sport_motocross/*.jpg','upload/sport_motocross/*.gif','upload/sport_motocross/*.png'}, GLOB_BRACE) as $file) {
   list($h, $w, $dmy1, $attr, $dmy2) = getimagesize($file);
   echo '<img src="' . $file . '" ' . $attr . "/><br />\n";
}
?>

 

Ken

Link to comment
Share on other sites

Ok I have one more problem. How can I get the images to display in rows of 5 instead of one above the other?

 

This is my code so far.

 

<?php
$d = dir("sport_motocross");
//echo "Handle: " . $d->handle . "\n";
//echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
   if ($entry == "." || $entry == "..") {
       continue;
   }elseif (!ereg('gif|jpg|jpeg|png', $entry)) {
       continue;
   }  
   echo "<img src=" . "http://www.designervision.co.nz/magik/gallery/sport_motocross/" .$entry. "\n" . "/>" . "<br />" . $entry. "<br />";

}
$d->close();
?>

Link to comment
Share on other sites

  • 3 years later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.