open file only if file exists<

liunx

Guest
<a href=http://www.htmlforums.com/archive/index.php/"images/photo<?php echo ($_GET['page']*4-3) ?>.jpg"><img src=http://www.htmlforums.com/archive/index.php/"images/photo<?php echo ($_GET['page']*4-3) ?>-t.jpg" class="pic" width="250" height="250" align="middle" alt=" " /></a>

I wrote this code, but would only like to execute it if the image that it displays actually exists. I tried the code below, with similar variations, but it didn't work.

<?php if (is_file("images/photo($_GET['page']*4-3).jpg")){ echo " ?><a href=http://www.htmlforums.com/archive/index.php/"images/photo<?php echo ($_GET['page']*4-3) ?>.jpg"><img src=http://www.htmlforums.com/archive/index.php/"images/photo<?php echo ($_GET['page']*4-3) ?>-t.jpg" class="pic" width="250" height="250" align="middle" alt=" " /></a><?php " ?>

What am I doing wrong?since you do your match several time, i suggest to put it in a variable


$image = $_GET['page']*4-3;
if (is_file('images/photo'.$image.'jpg')) {
echo '<a href=http://www.htmlforums.com/archive/index.php/"images/photo',$image,'.jpg"><img src=http://www.htmlforums.com/archive/index.php/"images/photo',$image,'-t.jpg" class="pic" width="250" height="250" align="middle" alt=" " /></a>';
}or use file_exists()instead of is_file
 
Back
Top