There are actually valid times to do this. (most people would never have a reason to, though).

In the case in question, the issue was that the files weren't in a directory that the webserver was directly serving. Of course, if that's the only issue, you can just symlink it in to a directory that is being served, or just map the images directory in the webserver.

Some people use this trick to ensure that someone can't link directly to their images. (eg, you have an image on your website that other people are trying to place in an <img> on their website. Or, any other time that you might have the image vary based on some parameter (randomizing, adjusting by time, or preventing it from being viewed too often is the main reason -- most other things, such as password protection, or varying by accept language, IP range or HTTP_REFERER you can handle through URL rewriting or otherwise through the webserver).

In some situations, you it might be that the images are actually stored in a database, and not just a file system, so you need to handle the retrieval. In some situations, you might also store the files compressed, and decompress them as they're requested. (this might not be advantageous for most file formats, but you can use this for other types of files, as well.)


In reply to Re^2: Displaying Image located outside web server dir by jhourcle
in thread Displaying Image located outside web server dir by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.