# \[php\] !file\_exists trouble

**URL:** https://forum.kirupa.com/t/php-file-exists-trouble/226270
**Category:** programming
**Created:** [May 19, 2007, 3:31pm UTC](https://forum.kirupa.com/t/php-file-exists-trouble/226270 "2007-05-19T15:31:48Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![thatguythatsme](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@thatguythatsme](https://forum.kirupa.com/u/thatguythatsme)
#### Post date: [May 19, 2007, 3:31pm UTC](https://forum.kirupa.com/t/php-file-exists-trouble/226270/1 "2007-05-19T15:31:48Z")

</div>

I’m having trouble with this code. I’ve got this code checking to see if an image exists, and if it doesnt display a an alternative image. It doesnt seem to be working and I cant seem to figure or why? any suggestions…

Cheers  
David

```php

<?php 
$file = the_title('','',false);
$imgPath = 'http://emotionaltherapy.flexlab.co.uk/wp-content/themes/default/images/' . $file . '.jpg'; ?>
<?php
if (!file_exists($imgPath)) { ?>
   <img src="/wp-content/themes/default/images/<?php the_title(); ?>.jpg" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" />
<?php } else { ?>
   <img src="/wp-content/themes/default/images/The Foundation for Emotional Therapy.jpg" alt="Emotional Therapy" title="Emotional Therapy" />
<?php } ?>

```
