Counting jpg files

Posted By: gal ()
Posted On: 2004-Oct-19 16:14

I have a thumbnail pic that allows you to click on it for additional pictures. That will take you to an html file that contains the additional pics. I created a php command that will pass the item_number to a php file that will dynamically create the additional pics page. This way, some work has been cut out.

The problem is that I will sometimes have 2, 4, 6, 8 additional pictures. All pics are named the same item_number-1.jpg, item_number-2.jpg--where the item_number is dynamic [but the same for every pic on the page], and the "1", "2", etc. is for each picture. Is there a way to check to see if the next picture number jpg exists in the folder, and stop if it doesn't? This way the page will be OK for any number of pictures.

I would rather not have different php files for the different number of pictures.


Posted By: gal ()
Posted On: 2004-Oct-19 17:33

Well, I thought I had found the solution. I have tried the following, and everything works fine except I get the error:

"The file http://www.mysite.com/graphics/rg874x400.jpg does not exist."

The file name is accurate and the file does exist?



Code: [copy]





I'm a bit baffled and don't know where to go from here.


Posted By: langard ()
Posted On: 2004-Oct-19 22:38

You might try something like this. You'll have to troubleshoot it 'cause I just wrote it here for you as an example.

The function checks to see if the file exists (up to ten pics), then puts it into an array and returns it.

The display calls the function, parses the array, gets the picture width and height, then outputs it to the screen.

//*************************
//Picture Function
//*************************

function ShowPics($ItemNum){
$PicArray = array();
for($i=0; $i<=10; $i++){
$Pic = $ItemNum . "-" . $i . ".jpg";
if(file_exists("/graphics/$Pic"wink){
$PicArray[] = $Pic;
}
}
return $PicArray;
}//endShowPics

//*************************
//Picture Display
//*************************

$DisplayPics = ShowPics($_POST["item_num"]);

foreach($DisplayPics as $PicKey => $PicFile){
$ImgSize = getimagesize($PicFile);
$ImgSizeX = $ImgSize[0];
$ImgSizeY = $ImgSize[1];

echo "<img src='$PicFile' width='$ImgSizeX' height='$ImgSizeY' alt='' border='0' vspace='5'><br>";
}//endforeach


[ Message was edited by: langard 10/19/2004 02:48 pm ]




Posted By: g1smd (Staff)
Posted On: 2004-Oct-30 16:15

Did that help?



Is your script looking in the right folder for the image?