View Full Version : Show all pictures in a directory
Spazze
December 1st, 2001, 05:19
I got a lot of images on F2S, I want to see them all like thumbnails but I dont want to put all the image URLs in the code. Do anyone know a script that would show all the images in the directory, so that I dont have to put them all in the code?:confused:
Dusty
December 2nd, 2001, 12:33
#!/usr/bin/perl
# URL to the directory where the images are
$url="http://www.yourname.f2s.com/images";
# Path to the directory where the images are
$path="/path/to/images/directory";
print "Content-type: text/html\n\n";
print "<h1>Images:</h1>";
opendir(DIR,$path);
@images=readdir(DIR);
closedir(DIR);
foreach $image(@images){
if($image=~/\.gif$/){
print "<a href=\"".$url."/".$image."\"><img src=\"".$url."/".$image."\" width=\"50\"></a>";
}
}
That would go through a directory and print out a page containing all the GIFs resized to 50 pixels wide with a link to them at full-size.
Spazze
December 4th, 2001, 12:34
I have to admit, I'm really a newbie. What should I do with this code? Should I compile it or something? Thanks alot for helping me out!:eek2:
Dusty
December 4th, 2001, 14:55
Just copy and paste that into Notepad or whatever, save it as "images.pl" (call it what you want, just make sure it's ".pl"), upload it anywhere on your F2S account, and it's ready to run. I don't think you need to CHMOD using F2S, but if you do it should be CHMODed 755.
The two variables at the top need editing as well, you can probably figure those out.
Spazze
December 5th, 2001, 08:41
When I saved the code as index.pl in my f2s directory and tried open it I got this message:
500 Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@spazze.f2s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
--------------------------------------------------------------------------------
Apache/1.3.19 Server at www.spazze.f2s.com Port 80
What could be wrong with it?
Here's the URL, if that could help you,
http://www.spazze.f2s.com/index.pl
Canuckkev
December 6th, 2001, 00:43
Hmmm...did you upload in ASCII? If not, make sure you set your FTP program to upload the file in ASCII, NOT binary. That's the first mistake I made using Perl!
Spazze
December 6th, 2001, 11:48
Now I uploaded the file in ASCII. But I don't see any images any way :( It just says "Images:"
Here's how the code look like:
#!/usr/bin/perl
# URL to the directory where the images are
$url="http://www.spazze.f2s.com/";
# Path to the directory where the images are
$path="/web/sites/256/spazze/www.spazze.f2s.com/";
print "Content-type: text/html\n\n";
print "<h1>Images:</h1>";
opendir(DIR,$path);
@images=readdir(DIR);
closedir(DIR);
foreach $image(@images){
if($image=~/\.gif$/){
print "<a href=\"".$url."/".$image."\"><img src=\"".$url."/".$image."\" width=\"50\"></a>";
}
}
I don't know if the directory path is correct? On the f2s members page it says that's the complete path "for use in cgi/php scripts".
Dusty
December 6th, 2001, 21:58
I just tested it, the script does work, so either the path is wrong or your images aren't GIFs. You can change what extension to look for by editing the:
if($image=~/\.gif$/){
...line. For example, to look instead for JPEGS change it to:
if($image=~/\.jpeg$/){
Spazze
December 7th, 2001, 01:41
YES! Now it works! Thanks alot guys!
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.