The pics dir

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
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

The pics dir

Post by cheatboy00 »

I was just wondering if any of you guys know how to get a pictures extenstion, (.jpg, .gif, etc ...), from the directory pics.

becuase in the pics dir there are pictures according to username, but each have a different extenstion. I know I can do this by create a big long if statement, but I have 100+ pics in that dir. Is there some sorta function that gets the extenstion?

please help.

all I have is this

Code: Select all

<?PHP
   echo "<img src="pics/$username.(inscert extenstion)" alt="$username" />";
?>
?>
MeOnTheW3
Forum Commoner
Posts: 48
Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB

Post by MeOnTheW3 »

Try this:

Put all the possible extentison you wish to allow in the direcory in an array and loop through it.

Code: Select all

&lt;?php
$ext=array();
$ext&#1111;0] = 'gif';
$ext&#1111;1] = 'jpg';
$ext&#1111;2] = 'jpe';
$ext&#1111;3] = 'png';
$ext&#1111;4] = 'bmp';

foreach($ext AS $index =&gt; $exVal)
{
   $file = $username . '.' . $exVal;

   if(is_file('./pics/'.$file))
   {
          echo '&lt;img src="pics/' . $file . " alt="' . $username . '" /&gt;';
   }
}
?&gt;
serg4444
Forum Newbie
Posts: 9
Joined: Fri Nov 22, 2002 10:27 am

Post by serg4444 »

Use a special function for that:
$ext=getimagesize($file);
if($ext[2]==1){$e=".gif";}
if($ext[2]==2){$e=".jpg";}
etc.
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

image size

Post by cheatboy00 »

That's I got that to work.

But is there a way to check that files image size. Because I want to create a preview file for the pics I do find. thanks for any help in advance.
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

The image's height and width are other array elements returned from the "getimagesize()" function. See:
http://www.php.net/manual/en/function.getimagesize.php
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

wicked thanks
Post Reply