Page 1 of 1
IMage code
Posted: Tue Apr 20, 2004 1:00 pm
by Turbo
Hi pro's!
I'm in a bad situation here , i made a website in php , with tables , pics and text.
Now this website is made for an foto studio , and the guy wants to put some images on his site for a preview of his work. But he nows <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> about websites so he cant change pics and things.
Now i've heard of a friend that there is a way via the FTP to put a map on it load some pics in it and the pics will be shown on the site... but how do you do that ? ANd can you set them in a table so there is a black border on them ?
PLzzz... Can someone help me ?
THX !
Posted: Tue Apr 20, 2004 2:52 pm
by John Cartwright
Code: Select all
<?php
$dir = "what/ever/you/want/";
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<img src='$dir/$file' border='1'>";
}
}
closedir($handle);
}
?>
This opens the directory you want, and echos each file.
Posted: Wed Apr 21, 2004 10:45 am
by Turbo
OMg thank you very much !!!
Still one question , can i make a link on the pictures ?
Posted: Wed Apr 21, 2004 11:15 am
by mudkicker
Code: Select all
<?
echo "<a href="$dir/$file"><img src='$dir/$file' border='1'></a>";
?>
Posted: Wed Apr 21, 2004 11:25 am
by vigge89
the code Phenom posted echos out an image-tag for each file in the directory, not only images. also, i think you want a thumbnail-system? Phenoms code just shows the images in whole, so if you have images in bigger resolutions, the page would look ugly and take long time to load.
Posted: Wed Apr 21, 2004 11:39 am
by JAM
vigge89 wrote:the code Phenom posted echos out an image-tag for each file in the directory, not only images. also, i think you want a thumbnail-system? Phenoms code just shows the images in whole, so if you have images in bigger resolutions, the page would look ugly and take long time to load.
...but displaying thumbnails, that themselves link to the BIG images would work... Depends on whats wanted.
Posted: Wed Apr 21, 2004 2:43 pm
by Turbo
Yeah that's what i mean , so i have a little picture and when you press it , it turns up bigger in a new page.Can this be done ?
Thanks guys for the reply's !
Posted: Wed Apr 21, 2004 3:39 pm
by JAM
Combine phenoms code with mudkickers...
Code: Select all
<?php
$dir = "/images/thumbs/"; // thumbs (duh)
$bigdir = "/images/"; // originalsized, using same names as thumbs
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<a href="$bigdir/$file"><img src="$dir/$file" border="1"></a>";
}
}
closedir($handle);
}
?>
Posted: Wed Apr 21, 2004 4:05 pm
by mudkicker
Code: Select all
<?
if ($file != "." && $file != "..")
?>
is this better than above?
Posted: Wed Apr 21, 2004 4:12 pm
by John Cartwright
Code: Select all
<?php
$i=1;
$dir = "/images/thumbs/"; // thumbs (duh)
$bigdir = "/images/"; // originalsized, using same names as thumbs
echo '<table>';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$i++;
// opens row and column is remainder is odd else open column
if ($i%2=='1'){ echo '<tr><td>'; }else{ echo '<td>'; }
echo "<a href="$bigdir/$file"><img src="$dir/$file" border="1"></a>";
// closes row and column is remainder is odd else close column
if ($i%2=='1'){ echo '</td></tr>'; }else{ echo '</td>'; }
}
}
echo '</table>';
closedir($handle);
}
?>
This will create a table displaying a table with 2 pictures per row and as many rows as needed. Also I had some good ideas for captions if you are interested.
[Edit: Fixed errors in both mine and this post, my fault. --JAM]