clbtech Posted December 8, 2016 Share Posted December 8, 2016 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"> Quote Link to comment https://forums.phpfreaks.com/topic/302706-mask-file-namepath-in-img-tag-with-php/ Share on other sites More sharing options...
requinix Posted December 8, 2016 Share Posted December 8, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/302706-mask-file-namepath-in-img-tag-with-php/#findComment-1540158 Share on other sites More sharing options...
Jacques1 Posted December 8, 2016 Share Posted December 8, 2016 Why do you think you need this? What is the “masking” supposed to do? Quote Link to comment https://forums.phpfreaks.com/topic/302706-mask-file-namepath-in-img-tag-with-php/#findComment-1540159 Share on other sites More sharing options...
Jacques1 Posted December 8, 2016 Share Posted December 8, 2016 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? Quote Link to comment https://forums.phpfreaks.com/topic/302706-mask-file-namepath-in-img-tag-with-php/#findComment-1540160 Share on other sites More sharing options...
requinix Posted December 8, 2016 Share Posted December 8, 2016 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 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. Quote Link to comment https://forums.phpfreaks.com/topic/302706-mask-file-namepath-in-img-tag-with-php/#findComment-1540161 Share on other sites More sharing options...
Jacques1 Posted December 8, 2016 Share Posted December 8, 2016 Sure. I was just trying to get more information from the OP in case the problem is legitimate but poorly described. 1 Quote Link to comment https://forums.phpfreaks.com/topic/302706-mask-file-namepath-in-img-tag-with-php/#findComment-1540162 Share on other sites More sharing options...
bsmither Posted December 16, 2016 Share Posted December 16, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/302706-mask-file-namepath-in-img-tag-with-php/#findComment-1540427 Share on other sites More sharing options...
Jacques1 Posted December 16, 2016 Share Posted December 16, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/302706-mask-file-namepath-in-img-tag-with-php/#findComment-1540429 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.