Jump to content

mask file name/path in IMG tag with PHP?


Recommended Posts

Is there a way I can mask a filename or path used in an HTML IMG tag using PHP?

 

What I'm looking to do is have something like this:

 

<IMG SRC="php_function(parameter)"/ >  or <IMG SRC="1234565">    (WHERE "1234565" is an ID that is processed by a PHP script to get the actual filename/path, but not actually show it in the HTML) instead of  <IMG SRC="filename.jpeg">

 

Link to post
Share on other sites

If PHP were to somehow obscure the path to the image, how would the browser know where to find it? Ultimately the browser needs to know because it's the one displaying the image.

 

So no.

Link to post
Share on other sites

For the record: You can hide file paths behind a separate PHP script which acts as a proxy.

<img src="img.php?id=c8aa0b77cb24a866e1987bae07955e69" alt="...">

However, this only makes sense if the script actually provides a benefit (access control, security, ...). If you merely map one file path to another file path, why not just rename the file?

Link to post
Share on other sites

For the record: You can hide file paths behind a separate PHP script which acts as a proxy.

I phrased my post specifically so someone might mention that :P I was then going to follow up with "yes, that may hide the path to the image file itself, but the image is still accessible in some form at that URL so it doesn't help much". At least doesn't help with what it sounds like OP wants to do.
Link to post
Share on other sites

Maybe just a smidgen more involved:

<i class="image" rel="index|hash"></i>

Have javascript (jQuery) collect up all the $(".image") objects, associate the rel attribute into a json array, ajax that to a PHP script, that will get the index and compare the pre-computed hash in a server-based filemanager setup, then return a base64 encoded binary response of actual image data, whereby the inner contents of the relevant <i> tag is filled with the image data using the "data:image/png;base64" format.

 

...I think.

Link to post
Share on other sites

All that does is make the site inefficient by preventing the client from caching the images. It's also disastrous in terms of usability and accessibility, because if the user is visually impaired or simply has JavaScript disabled, the whole <i> stuff makes no sense whatsoever. I can only imagine how that works with a screenreader: “Here's empty text, no, wait, now it's an image.”

 

If you don't reserve the image space, the layout will also jump around wildly as the images are loading.

 

And again: As long as we don't know what the user wants, this is all just speculation.

Link to post
Share on other sites
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.