Jump to:

23459 Posts in 18906 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Detecting broken image links

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 537 Views
  • Bereusei
    Community Member
    94 Posts

    Detecting broken image links Link to this post

    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;
       $currentUrl = window.location.pathname;
          $.post("themes/mytheme/php/send.php", { brokenimage: $currentUrl } );
             $check = true;

    for the send.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
       $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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.