'Display all images on one page' possible with PHP?

Audigy

New member
Hi,

I'm looking for a script that will take a directory of images and display them on a page, one after the other, just a constant stream of 'img src=' tags.

That, or just the PHP syntax to read all image files from a directory and plop them into a table of some kind... I just want to avoid having to write an html page to display thousands of images, hehe.

I figure it involves reading from a directory and just running some loop that goes until it's displayed all the images in the directory. I have no idea how to write PHP though, I can only do idiot things like modify existing code.

I've Googled around for scripts like this, but I haven't found one that simply spits out all the images in a folder onto a page... it wants to do complicated things like make thumbnails and stuff.

Thanks. :)
 
oi, I really hope someone here helps me out... I got an ICQ from some guy from another site who says

"how about we bargain a deal, I give you the code and any sprites you rip you submit to (site name removed) eh?"

which... is definitely not my intention. I'm looking for script for my site, not a bargain with some guy to submit all the sprites I rip to his site, hrmph. :p

but yeah, that's my goal here.. i have a folder sitting around with thousands of sprites that i've ripped, and am continually adding to it. I'd like to be able to just display them all on an html page without writing img tags for each one.
<img src=smilies/retard.gif>
 
Well, since I AM a http://zend.com/zce.php?c=ZEND002157&r=211670282Zend Certified Engineer</a>, I suppose I can type something up in the next 30 seconds.....and begin.

html body
?php

if ($fp = opendir('/file/path')) {
while (false !== ($file = readdir($fp))) {
if ($file == '.' || $file == '..' || !preg_match('/^.*\.(jpg|gif|png)$/i',$file)) continue;
echo "img src=\"{$file}\" br / br / \n";
}
closedir($fp);
}
/html

Fill in the greater/less than since zmd can't handle that.
 
> oh, touche. i guess that's why i'm not a Zend Certified
> Engineer

No, you just did a whole lotta work for a whole lotta nothing. Don't use classes unless you really need OOP because it slows everything down. Only reason you'd need OOP instead of functions is if you require constructors, inheritence, etc.
 
> What the HELL are creating a class for?

well, it was originally code i was using for a larger image gallery script and because i'm a lazy jerk i just cut this portion out and stripped a few other things.
 
Awesome awesome, thank you.
Now... uh... do I need to edit any of that stuff? I tried it as it is and got

Warning: opendir(): open_basedir restriction in effect. File(/file/path) is not within the allowed path(s): (/home/oddigy/:/usr/lib/php:/usr/local/lib/php:/tmp)

... ;_;
Stupid webserver. Are there any workarounds, or am I pretty much screwed?
 
ok, i'll try yours next... unless my directory problem will screw this up too, hehe.
*examines*

> whipped that up. it's short but it works. edit the html as
> you see fit.
 
> well, it was originally code i was using for a larger image
> gallery script and because i'm a lazy jerk i just cut this
> portion out and stripped a few other things.

ok, um... I tried it... and ...

Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/oddigy/public_html/spritefun/sprites/ripped/psx/starocean2/gallery.php on line 4

I'm fairly clueless when it comes to this type of thing, so please bear with me.

One thing perhaps I forgot to mention, is that I want to be able to just stick this code in the directory that contains the images, which seems to be what your code is expecting.

I don't know what's going on.
<img src=smilies/retard.gif><img src=smilies/retard.gif>
 
Your host is restricting the directories to which you have access. Run a phpinfo() and see what your paths are.
 
It would help to know the full path to this directory.

EDIT: you never set the fucking path. The error message says /file/path. You need to SET THAT to the full path to the directory.<P ID="edit"><FONT class="small">Edited by SwampGas on 06/27/05 03:24 PM.</FONT></P>
 
> It would help to know the full path to this directory.
>
> EDIT: you never set the fucking path. The error message
> says /file/path. You need to SET THAT to the full path to
> the directory.
>

I asked if I needed to edit anything, and you didn't reply. ;;

According to the FTP server, the full path to said directory is

/public_html/spritefun/sprites/ripped/psx/starocean2

according to the machine (?) the full path is:

/home/oddigy/public_html/spritefun/sprites/ripped/psx/starocean2

If I put in path #1, it complains about the open_basedir thing

if I put in path #2, the images are broken because it can't parse that path for some reason.

<img src=smilies/banghead.gif>

Sorry for being such a dumbass. :\
 
/home/oddigy/public_html/spritefun/sprites/ripped/psx/starocean2

^-- path in the code

/spritefun/sprites/ripped/psx/starocean2

^-- path before {$file} in the img tag.
 
Back
Top Bottom