Page 1 of 1

The pics dir

Posted: Sat Nov 30, 2002 3:00 pm
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" />";
?>
?>

Posted: Sat Nov 30, 2002 4:10 pm
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;

Posted: Mon Dec 02, 2002 3:34 am
by serg4444
Use a special function for that:
$ext=getimagesize($file);
if($ext[2]==1){$e=".gif";}
if($ext[2]==2){$e=".jpg";}
etc.

image size

Posted: Mon Dec 02, 2002 1:36 pm
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.

Posted: Mon Dec 02, 2002 3:24 pm
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

Posted: Mon Dec 02, 2002 4:57 pm
by cheatboy00
wicked thanks