Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7611487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:40:40+00:00 2026-05-31T01:40:40+00:00

I am currently using the php file_exist method to check if an image exist

  • 0

I am currently using the php file_exist method to check if an image exist and to display the default image if it doesn’t:

if(file_exists($image_location))
{
 echo "<img src='$image_location'>";
}
else
{
 echo "<img src='default_image.jpg'>";
}

Other than doing the above, I know that can:

1) Style the <img> tag with a background image

2) Use javascript onerror method to replace the missing image

If the image is hosted remotely,

3) Generate a HEAD request using cURL to detect the presence of the image or

4) Use the jquery ajaxComplete event

I think each method has its advantages and disadvantages. My long-term intention is to host the image separately, so all four options should be feasible. But which would be the better one and why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:40:41+00:00Added an answer on May 31, 2026 at 1:40 am

    A file_exists() check for each image on each page requests sounds extremely over-the-top; is your environment that unstable!?

    #1 and #2 sound like your best bet. Out of those 2, I’d choose #2 as a background image has different behaviour to the src attribute (e.g. how the image is resized/ repeated if it doesn’t fit within the image bounds).

    Be sure do avoid doing #3 for each image for each request; you’ll slow down your page load infinitely (making a HTTP connection for each image on the page). If you want to do this, consider having a task which runs on a cron which does this for you.

    Ultimately, you shouldn’t be in an environment where images are becoming unavailable so often.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using PHP, JAVASCRIPT, MYSQL, XHTML, CSS to develop my site. Note that
I am currently using PHP/MySQL and the jQuery timeago plugin. Basically, I need to
I'm currently using the following PHP code: // Get all subordinates $subords = array();
I am currently using various back-end services and I want to use PHP to
I'm reading some XML with PHP and currently using the DOMDocument class to do
I'm currently developing a website which stores bookmarks in a MySQL database using PHP
How can I setup expires headers in PHP + Apache? I'm currently using an
What's the most efficient way to resize large images in PHP? I'm currently using
I'm currently developing a PHP application that's using an Access database as a backend.
I'm working with generating .pdf's from PHP using this library: http://www.fpdf.org/ I am currently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.