Universal If-Image-Exists Script?

I got hit with a weird problem a few days ago. If I preview a web page with a bad image link (in other words, no image displays), it sucks up all my memory until my computer crashes. I’m using a MacBook Pro with CS3 and MAMP. I erased my hard drive and reinstalled OS X and MAMP, then copied over my database and one website. It didn’t fix anything.

So it occurred to me that an awesome workaround would be a script that detects images and, if there is no image (bad link), then the script would kill that link and display a warning instead.

But I can’t do it link by link. Is there some sort of universal PHP script I could insert in my head section that would handle every image on my site, either displaying the image or zapping the link entirely?


Why can’t you do it link by link?

I would use a “If the image exists display the image otherwise display a default image or nothing.”

The better thing to do is check your website for broken links and fix them. There is software around to do the checking for you.

Not to mention that a missing link should in no way suck up memory. You might want to try a different webbrowser.

Not sure why you went to such great lengths (erasing your HDD and reinstalling your OS) to fix an issue which clearly comes from your web browser… Have you installed or updated any plugins/user scripts in your web browser recently? Is your web browser completely up-to-date? Is this problem of browser freezing due to broken images occurring on any website with a broken image, or just certain websites in particular?

The problem happens with ALL browsers - Chrome, Firefox, Opera and Safari.

I can’t fix it link by link because my articles are stored in a database, where I can’t use PHP.

Of course, the ultimate fix, as you suggested, is to just fix the broken links. I’m working on it right now. But it’s just kind of a nuisance when my memory crashes every time I preview a page that has a link I haven’t fixed yet. (I recently upgraded my websites, changing all links to lowercase and replacing underscores with dashes; that’s why many older links aren’t working.)

It appears that there are some pages that crash even though the images display correctly. The catch is they’re images linked to a different website. Also, I found one page that apparently crashed because it was linked to a JavaScript file on another site (or perhaps the JS file included a link to a missing image).

It’s a little confusing, but the problem didn’t exist until recently. I’m going to learn how to disable Apple’s server, which may be somehow competing with the MAMP server. I saw that suggestion during a Google search.

I’ll have to check out the software checks for broken links, too. Thanks for the tips.