Showing All Images In Folder
Posted: Sun Aug 10, 2008 8:09 pm
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?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Pause between firing rounds.CoolAsCarlito wrote:The only thing is I don't want my images listed. I actually want them shown.
Code: Select all
<?php
$path_to_images = 'images/';
$images = scandir($path_to_images);
foreach($images as $image)
{
print '<img src="' . $path_to_images . $image . '" />';
}
?>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 . '" />';
}
?>
A forward slash in your $path_to_images variable (at the end).CoolAsCarlito wrote:What am I missing?
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");