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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpDK
Forum Newbie
Posts: 1
Joined: Sun Jan 25, 2009 3:37 am

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

Post 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 :-)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
Post Reply