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 787465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:12:22+00:00 2026-05-14T21:12:22+00:00

I currently have code like this in a web based file called ‘view_file.php’ to

  • 0

I currently have code like this in a web based file called ‘view_file.php’ to grab an image from an internal network.

<img src="put_file.php?type=<?=$TN_TYPE;?>&path=<?=$TN_PATH;?>&filename=<?=$TN_FILENAME;?>" />

The ‘put_file.php’ script allows access to an internal server that we don’t want to expose to the internet. This script checks to see if an image is available and if it is, sends an image header and then uses readfile() to stream the image to the ‘view_file.php’ page.

The problem is if there isn’t an image available, instead of streaming a temporary ‘spacer.gif’ i want to not have the img tag written at all.

Any Ideas how to do this?
I’m thinking maybe move the img tag into the ‘put_file.php’ script, but how to mix strings and steams?

  • 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-14T21:12:22+00:00Added an answer on May 14, 2026 at 9:12 pm

    Can’t be done simply I think.

    • You could make a call to put_file.php in PHP, see what it returns, and if it returns an empty value (or a 404 header or whatever) refrain from writing the img tag. Obvious con: The request is made twice, and it complicates the script.

    • You could create the image element in JavaScript depending on the result of an Ajax call to put_file.php. Obvious con: Doesn’t show up straight after loading, and needs JavaScript.

    Both these options could be reduced to making one request by piping the results of the testing request into base64-encoded data: URI’s, but that is highly incompatible (no IE support) and bloats the page on browser side (the image data plus 33% overhead would be present straight in the source code, or the JavaScript memory, respectively). I wouldn’t recommend it.

    If at all possible, I personally would stick with the spacer.gif solution.

    Update: One other idea, if it’s just that you don’t want the images to appear, would be sending a 404 header when the image isn’t there, and utilizing the onerror event of the img tag to, say, do a <img onerror='this.style.display = "none"'>. Requires Javascript, of course. The error event seems to be fully supported in all browsers (reference here, german only sorry, but you’ll see the icons :).

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

Sidebar

Ask A Question

Stats

  • Questions 424k
  • Answers 424k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Tuples originated in functional programming. In (purely) functional programming, everything… May 15, 2026 at 11:49 am
  • Editorial Team
    Editorial Team added an answer In most cases it is better to have a separate… May 15, 2026 at 11:49 am
  • Editorial Team
    Editorial Team added an answer You just need to remove the quotes (otherwise it's looking… May 15, 2026 at 11:49 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.