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

  • Home
  • SEARCH
  • 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 493k
  • Answers 493k
  • 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 Both UserNamePasswordValidator and MembershipProvider perform the same thing - they… May 16, 2026 at 10:53 am
  • Editorial Team
    Editorial Team added an answer There isn't anyway to automatically download an entire folder (or… May 16, 2026 at 10:53 am
  • Editorial Team
    Editorial Team added an answer You can use dot or square bracket notation: var obj… May 16, 2026 at 10:53 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

Related Questions

Currently my AJAX is working like this: index.php <a href='one.php' class='ajax'>One</a> <div id=workspace>workspace</div> one.php
I'm currently attempting to read information about an object from the web.config file and
This is how I currently compile my code: jar cvf client.jar tileGen.class tileGen$GamePanel.class Player.class
I currently have a class of this form: class Abc { private readonly IDisposable
I am creating a web interface which currently reads data in from an XML
I have a plain XCode CoreData enabled iPhone/iPad navigation application. In this I have
I run a small blog network and on this I have a page where
I have an existing ASP.NET MVC application and am using StructureMap as my IOC
I'm currently in the process of researching the best development and deployment practices for
Perhaps this is a stupid question, but I'm trying to use BGL's dijkstra_shortest_paths ,

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.