Log in

View Full Version : Display all images in [folder]



Flumples
05-04-2007, 08:08 PM
Anyone know how I can have a simple page that'll display every single image in a certain directory.

for example...

www.mysite.com/images.php (http://www.mysite.com/images.php)

would display every single image in

www.mysite.com/images (http://www.mysite.com/images)

Nothing fancy, as long as it does the job that's fine :)


EDIT: Scrap that, this does the trick:


<?php
// Note that !== did not exist until 4.0.0-RC2

if ($handle = opendir('/path/to/image/directory')) {
echo "Directory handle: $handle\n";
echo "Files:\n";

/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
echo "<img src='http://www.mysite.com/images/";
echo "$file\n";
echo "'><br />";
}

/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
echo "$file\n";
}

closedir($handle);
}
?>

Verrou
05-04-2007, 09:34 PM
Warning: opendir() [function.opendir]: open_basedir restriction in effect. File(/path/to/image/directory) is not within the allowed path(s): (/home/andre:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/andre/public_html/uploader/images.php on line 4

Warning: opendir(/path/to/image/directory) [function.opendir]: failed to open dir: Operation not permitted in /home/andre/public_html/uploader/images.php on line 4

Huh?

Mentor
05-04-2007, 10:58 PM
Warning: opendir() [function.opendir]: open_basedir restriction in effect. File(/path/to/image/directory) is not within the allowed path(s): (/home/andre:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/andre/public_html/uploader/images.php on line 4

Warning: opendir(/path/to/image/directory) [function.opendir]: failed to open dir: Operation not permitted in /home/andre/public_html/uploader/images.php on line 4

Huh?
You have to change /path/to/image/directory), to what it says, in your case i think that would be /home/andre/public_html/ . possibly with an image folder name on the end if your useing one

Verrou
05-04-2007, 11:23 PM
Warning: opendir(http://andrehamon.evenhosting.com/uploader/images/) [function.opendir (http://www.andrehamon.evenhosting.com/uploader/function.opendir)]: failed to open dir: not implemented in /home/andre/public_html/uploader/images.php on line 4

Uh?

Florx
06-04-2007, 04:10 AM
Warning: opendir(http://andrehamon.evenhosting.com/uploader/images/) [function.opendir (http://www.andrehamon.evenhosting.com/uploader/function.opendir)]: failed to open dir: not implemented in /home/andre/public_html/uploader/images.php on line 4

Uh?
Lol change it to:

/home/andre/public_html/uploader/images

or try chmoding the images to 777 - might work i dunno lol

Verrou
06-04-2007, 06:22 AM
Ok got it working, thanks very much +rep to all!

Want to hide these adverts? Register an account for free!