IMage code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Turbo
Forum Newbie
Posts: 3
Joined: Tue Apr 20, 2004 1:00 pm

IMage code

Post 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&#39;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 !
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
Turbo
Forum Newbie
Posts: 3
Joined: Tue Apr 20, 2004 1:00 pm

Post by Turbo »

OMg thank you very much !!!
Still one question , can i make a link on the pictures ?
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

Code: Select all

<?
 echo "<a href="$dir/$file"><img src='$dir/$file' border='1'></a>"; 
?>
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
Turbo
Forum Newbie
Posts: 3
Joined: Tue Apr 20, 2004 1:00 pm

Post 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 !
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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);
}

?>
Last edited by JAM on Wed Apr 21, 2004 4:29 pm, edited 1 time in total.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

Code: Select all

<?
if ($file != "." && $file != "..")
?>
is this better than above?

Code: Select all

<?
if (!is_dir($file))
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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]
Post Reply