You are here:  » Images returning "404 Not Found"


Images returning "404 Not Found"

Submitted by babyuniverse on Sat, 2013-09-14 01:34 in

Hi There,

One of my affiliaes is returning images that say "404 Not Found"
{link saved}

Any idea how to return noimage.jpg on that result?
I am using

<div class="product-image">
 <?php if ($mainProduct["image_url"]): ?>
          <img src='<?php print $mainProduct["image_url"]; ?>' alt='<?php print $mainProduct["name"]; ?>' />
        <?php else: ?>
          <img src='<?php echo $config_baseHREF?>images/noimage.jpg' />
        <?php endif; ?>
</div><!-- product-image -->

Thanks
Richard

Submitted by support on Sat, 2013-09-14 10:29

Hi Richard,

Since there is no (efficient) way to tell that images are returning 404 at the time of page generation, the best solution in this case is to use the JavaScript onerror event of the associated IMG tag; so where you have:

<img src='<?php print $mainProduct["image_url"]; ?>'

...try something like:

<img onerror='JavaScript:this.src="/images/noimage.jpg";' src='<?php print $mainProduct["image_url"]; ?>'

I'm looking into your other query regarding limiting random Featured Products to no more than n from the same merchant - i'll follow up to that once I've done some experiments...

Cheers,
David.
--
PriceTapestry.com