How to check whether file exists on server

I am building a dynamic photo gallery and have run into a problem.

I am using next and previous buttons. This code, for instance, is for the next button.

 _global.picnumber = picnumber +1;

Obviously I can only have a set amount of pictures so I need to check whether or not the file exists on my server. If it does not exist, it has to load “1.jpg”
The reason I want to check is that I would like to just upload pictures in a sequential order and not touch my fla.

Can someone help me out with a nice if statement that checks whether or not a file exists?

yes, someone can, and his name is PHP…
Flash alone can’t do that, PHP can read all the files in a directory, and if you want, send the list to the swf. See server-side forum for details.
If you don’t want to use a scripting language, then you’ll need to use a text, or better xml config file which you update manually and flash reads in to set up the image viewer.
can be as simple as
< files total=10 / >

PHP also has a file_exists function, that immediately checks if a file exists or not. A lot shorter than getting a list and running through it to see if it’s in there.
There is also a way to check it from Flash, using the LoadVars object. FlashGuru has an article on it I think … yup:

I was thinking it might be PHP or some server side tomfoolery, thanks for the replies. Its time to do some research…