Page 1 of 1

Showing All Images In Folder

Posted: Sun Aug 10, 2008 8:09 pm
by CoolAsCarlito
Okay I want my photos.php file to show all the photos I have in my /kowphotos/ folder on my server. How do I go out having that done?

Re: Showing All Images In Folder

Posted: Sun Aug 10, 2008 11:35 pm
by califdon

Re: Showing All Images In Folder

Posted: Tue Aug 12, 2008 2:17 pm
by CoolAsCarlito
The only thing is I don't want my images listed. I actually want them shown.

Re: Showing All Images In Folder

Posted: Tue Aug 12, 2008 2:43 pm
by flying_circus
CoolAsCarlito wrote:The only thing is I don't want my images listed. I actually want them shown.
Pause between firing rounds.

Re-read that link that califdon post and try to think of a clever way to use that returned information to solve your problem.

Code: Select all

<?php
  $path_to_images = 'images/';
  $images = scandir($path_to_images);
 
  foreach($images as $image)
  {
    print '<img src="' . $path_to_images . $image . '" />';
  }
?>

Re: Showing All Images In Folder

Posted: Tue Aug 12, 2008 3:16 pm
by CoolAsCarlito

Code: Select all

 
<?php
  $path_to_images = 'images/kowphotos';
  $images = scandir($path_to_images);
 
  foreach($images as $image)
  {
    print '<img src="' . $path_to_images . $image . '" />';
  }
?>
 
What am I missing?

Re: Showing All Images In Folder

Posted: Tue Aug 12, 2008 3:24 pm
by flying_circus
CoolAsCarlito wrote:What am I missing?
A forward slash in your $path_to_images variable (at the end).

Re: Showing All Images In Folder

Posted: Tue Aug 12, 2008 3:27 pm
by CoolAsCarlito
Okay I did that but what does this error mean?

Fatal error: Call to undefined function: scandir() in /home/content/y/a/n/yankeefaninkc/html/kowphotos2.php on line 3

Re: Showing All Images In Folder

Posted: Tue Aug 12, 2008 4:51 pm
by jazzfan
that means you don't have php 5...
you can use system directive, and you should make a simple recruisive algorithm to scan subfolders....
this is solution for linux/unix operatin systems....

Code: Select all

 
function rek ($path) {
     $output = system ("ls -1 $path", $status);
 
     //if failed to run above command (probebly premission denied)
     if ($status != 0) return;
     
     $ls = split ("\n", $output);
     foreach ($ls as $file) {
          // if "file" is a directory
          if ((int) system("file ${path}/${file} | grep 'directory' | wc -l") == 1)
                rek ("${path}/${file}");
          else if ((int) system("file ${path}/${file} | grep 'image' | wc -l") == 1)
               echo "<img src='${path}/${file}' />";
     }
}
 
//you call function using:
rek ("path/to/images/folder");
 

Re: Showing All Images In Folder

Posted: Tue Aug 12, 2008 5:12 pm
by nowaydown1
I believe that glob (http://us3.php.net/glob) is also available on PHP 4.