Page 1 of 1

<a href> address needs to accept two file formats.

Posted: Sun Jan 25, 2009 3:46 am
by phpDK
Hello forum :-)

In this link for opening an image, I need it to be able to check if $number.JPG exists, and if it doesnt open $number.html instead.

$pictureicon ="<A href='/graphics/catalog/$number.JPG' rel='shadowbox;height=480;width=640'(this, $number)>

Is this something that's in any way possible? I was thinking something along the lines of making an array : $extension = array("JPG", "html"); and then putting $extension instead of .JPG in the link, but i cant get it working.

I thought of another solution with an if statement, where the code checks if the $number.JPG is opened successfully, else it opens $number.html ... again i just cant get it working.

Any ideas for my little issue? Thanks in advance :-)

Re: <a href> address needs to accept two file formats.

Posted: Sun Jan 25, 2009 5:37 am
by requinix
Could use URL rewriting, wouldn't have to do this for every single one.

In your script use file_exists to check if the file already exists: yes, use the .jpg form, no, use the .html form.