I have a set of articles in Drupal 7, each with a field for an image. If I remove an image from FTP, or it becomes corrupt, or for some reason it's not at the location it thinks it is, the site will display the alt text and appear broken. I would like to tell Drupal to do something else in this case, like display a 'filler' or 'default' image. Is there a way to do that?
I tried doing a 'if file exists' statement in php but it won't let me write it. I tried adding a case for if no output is presented, but that only works for empty output, not output which points to an invalid file. I haven't found anything else in my research which allows me to do this in Drupal.
Please note this is not an action for when there is no image provided. This is for when an image IS provided but it doesn't exist. I want the site to fail gracefully.
Thanks! Brendan
In hook_field_display_alter you can check for file_exists and show a default image
In template_preprocess_node
pass the uri
value of the image variable to file_create_url. This will get you the absolute path to the image.
Then use PHP's file_exists function to verify its existence of the image path. Assign this to a variable $variables[image_exists] = file_exists($image_path);
Then in your node article template file:
if ($image_exists) {
// render $content['field_image']
} else {
// render some other markup
}