show image with its size on php

 Hello there experts,
  I have a folder called skating that has 20 pictures,
  I don’t want to make 20 pages like
  image1.html image2.html image3.html etc....
  is there anyway to make some index.php that can output
  for me the image and put 1 2 3 4 5 Next >>> for the other
  images? Lets say i have 20 images and instead of showing them
  all, just show each one per page in the same index.php
  all my images are .jpg so i don’t have to specify which images
  to output, so i would like to have the same size as the image
  if the image is 600x500 or 1200x300 show the size they have
  is that possible? =/
XtryAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

XtryAuthor Commented:
this is the example of my baseball page the image01.html
I only have 4 images in that folder

<html>
<head>
<title>baseball</title>
</head>
<BODY bgcolor="#406F9D">
<div align="center">
<img src="01.jpg" width="700" height="500">
<BR>
  <a href="baseball01.html"><font color="#CCCCCC" size="2" face="verdana">1 </font></a>
  <a href="baseball02.html"><font color="#CCCCCC" size="2" face="verdana">2 </font></a>
  <a href="baseball03.html"><font color="#CCCCCC" size="2" face="verdana">3 </font></a>
  <a href="baseball04.html"><font color="#CCCCCC" size="2" face="verdana">4 </font></a>
  <a href="baseball02.html"><font color="#CCCCCC" size="2" face="verdana">Next >>>
  </font></a></div>
</body>
</html>
0
XtryAuthor Commented:
I'm just looking for an easy way thats all.
Is that it takes a lot of time to make 100
.html when I take 100 pictures
0
cLFlaVACommented:
something like this (untested) may do the trick:

$id = isset($_GET['i']) ? $_GET['i'] : 1;
$pic_array = scandir('/path/to/images');
$count = 1;

echo '<img src="/path/to/images/' . $id . '">';

for ($i = 0; Ii < count($pic_array); $i++) {
    if ($pic_array[$i] != '.' && $pic_array[$i] != '..') {
        echo '<a href="index.php?i=' . $pic_array[$i] . '">' . $count . '</a> ';
    }
}

echo '<a href="index.php?i=' . $count + 1 . '">Next &raquo;</a> ';
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

cLFlaVACommented:
Forgot to increase the counter:

for ($i = 0; Ii < count($pic_array); $i++) {
    if ($pic_array[$i] != '.' && $pic_array[$i] != '..') {
        echo '<a href="index.php?i=' . $pic_array[$i] . '">' . $count . '</a> ';
        $count = $count + 1;
    }
}
0
cLFlaVACommented:
And this:

echo '<a href="index.php?i=' . $count + 1 . '">Next &raquo;</a> ';

Should really be this:

echo '<a href="index.php?i=' . $id + 1 . '">Next &raquo;</a> ';
0
KvdnBergCommented:
If you're using image names with 2 digits like your example (01 etc), you will need to add a 0 to 1 - 9 in the given code cy CLFlaVA

So it will become this:

if (strlen($id) == 1 {
$id = "0" . $id;
}
echo '<img src="/path/to/images/' . $id . '">';
0
cLFlaVACommented:
I think you are mistaken...

I have used scandir() which loads an array of filenames from the directory.

I then looped through the file names, and, as long as they weren't . or .. i use the file name as a whole, passed through the url.

I then use that file name to display the image.
0
hernst42Commented:
Just as note scandir is only available in PHP5, but ist the same as:

$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
   $pic_array[] = $filename;
}
closedir($dir);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cLFlaVACommented:
thanks hernst.  hadn't noticed that.
0
BenMorelCommented:
If you want to know the size of the image, you can call getimagesize() (does not require GD lib) :
<?php
list ($width, $height) = getimagesize('/path/to/image.jpg');
// Now you can use $width & $height !
?>

See ya ;)
Ben
0
hernst42Commented:
To let the images get as big as they are just leave the width and hight attributes away from the img tag. The brwoser then will show them as big as they are. So you don't need to check the sizes via php just use

<img src="01.jpg">
0
XtryAuthor Commented:
I get this error
Fatal error: Call to undefined function: scandir() in /home/website/baseball/index.php on line 8

<html>
<head>
<title>baseball</title>
</head>
<body>
<?PHP
$id = isset($_GET['i']) ? $_GET['i'] : 1;
$pic_array = scandir('/home/website/baseball/');
$count = 1;

echo '<img src="/home/website/baseball/' . $id . '">';

for ($i = 0; Ii < count($pic_array); $i++) {
    if ($pic_array[$i] != '.' && $pic_array[$i] != '..') {
        echo '<a href="index.php?i=' . $pic_array[$i] . '">' . $count . '</a> ';
        $count = $count + 1;
    }
}
echo '<a href="index.php?i=' . $id + 1 . '">Next &raquo;</a> ';
?>
</body>
</html>
0
KvdnBergCommented:
Like  hernst42  said, scandir is a php5 function. He suggests another way to handle it.
0
cLFlaVACommented:
utilizing henst42's suggestion:

<?PHP
$id = isset($_GET['i']) ? $_GET['i'] : 1;

$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
   $pic_array[] = $filename;
}
closedir($dir);

$count = 1;

echo '<img src="/home/website/baseball/' . $id . '">';

for ($i = 0; Ii < count($pic_array); $i++) {
    if ($pic_array[$i] != '.' && $pic_array[$i] != '..') {
        echo '<a href="index.php?i=' . $pic_array[$i] . '">' . $count . '</a> ';
        $count = $count + 1;
    }
}
echo '<a href="index.php?i=' . ($id + 1) . '">Next &raquo;</a> ';
?>
0
XtryAuthor Commented:
thank you guys
0
XtryAuthor Commented:
oh but i still get an error Warning: readdir(): and Warning: closedir():
0
BenMorelCommented:
Did you put a line :
$dir = "/path/of/your/photo/dir";
0
XtryAuthor Commented:
yes, but when i put that line it shows me a lot of numbers and the
scroll bar never stops going down and keeps showing me some
numbers.
0
XtryAuthor Commented:
1 2 3 4 5 6 7 8 etc...... until i stop it
0
cLFlaVACommented:
What is Ii?   It should just be i in the for loop, not Ii
0
cLFlaVACommented:
which was my mistake.
0
RoonaanCommented:
Always nice to see people having tested the stuff before the put it on the web *thumbsup*

-r-
0
arantiusCommented:
http://www.google.com/search?q=image+gallery+php
Results 1 - 10 of about 3,720,000 for image gallery php

Yes, a few people have wanted to do this before.  There's a lot of free image gallery scripts around.
0
cLFlaVACommented:
sarcasm necessary.
my purpose here is not to provide fully operable solutions for people, Roonaan, but rather to point them in the right direction.

always nice to see people making unnecessary comments at unnecessary times.
0
cLFlaVACommented:
*especially* when I even specified that I had not tested the code.

I'll be sure to make you very aware the next time you make a mistake on here.
0
RoonaanCommented:
Well, of course I understand you want to direct people in a good direction ClFlaVA, and your are indeed doing that realy often.

I just intended to point out that although scripting everything by hand is one solution, you should work it out properly before posting, or either state - like arantius did -, to use a already thought out widely available gallery.

This way you would show expertise as to judge when problems need a custom solution or can use a general solution. The general solution offering much more perspective in this case.

-r-
0
suresh_aspCommented:
Try this

simple one

<?php
if (isset($_GET['current'])){
      echo "page ".$_GET['current']."<br>";
?>
<img src="/imgs/image<?php echo $_GET['current'];?>.jpg"><br>
<?php
      list($width, $height) = getimagesize("/home/pricedunk/www/imgs/image".$_GET['current'].".jpg");
      echo "<b>Width: ".$width."</b><br>";
      echo "<b>Height: ".$height."</b><br>";
}

$fileCount = 0;
if ($handle = opendir('/home/pricedunk/www/imgs/')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != ".." && !is_dir($file) && substr($file,-3) == "jpg") {
                  $fileCount++;
        }
    }
    closedir($handle);
}

for($i=1;$i<=$fileCount;$i++){
?>
      <a href="?current=<?php echo $i; ?>"><?php echo $i; ?></a>
<?php } ?>
0
suresh_aspCommented:
Please note: with respect to above code and change path

As you are specific regarding image names like

image1.jpg, image2.jpg etc

and images path should be changed to your images directory
0
XtryAuthor Commented:
thank you very much!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.