Hey guys,
I´ve a silverstripe-website with hundreds of images. Anyway, sometimes the links to images gets broken (no idea why). The result is, that users see a white paper thing instead of the image. But I´ve created a little jquery-php solution:
for the javascript that appears on every site:
$check = false;
$("img").error(function(){
$currentUrl = window.location.pathname;
if(!$check){
$.post("themes/mytheme/php/send.php", { brokenimage: $currentUrl } );
$check = true;
}
});
for the send.php:
<?php
$brokenimageposition = $_POST['brokenimage'];
$brokenimageposition = stripcslashes($brokenimageposition);
$brokenimageposition = htmlspecialchars($brokenimageposition);
##Send activation Email
$subject = "Broken image link";
$to = "your@email.com";
$message = "Broken link is detected on the following site: \n
http://www.mysite.com$brokenimageposition";
$headers="From: error@mysite.com\n";
$headers.="MIME-Version: 1.0\n";
$headers.="Content-Type: text/plain;\n\t charset=\"utf-8\"\n";
$headers.="Content-Transfer-Encoding: 8bit\n";
$headers.="X-Sender: error@mysite.com\n";
$headers.="X-Mailer: PHP\n";
$headers.="X-Priority: 3\n";
mail($to, $subject, $message, $headers);
?>
This should work for any other 40X-error as well. I hope it is useful for someone.