Jump to content

Hide image URL/path from user


aeonsky

Recommended Posts

Hello!

 

I've look around Google for an answer, but I couldn't get anything conclusive...

 

Is the only way to hide the image url/path from user, like this below:

 

<img src="index.php/images/disp.php?image=004

 

Is to use the PHP image functions to recompress it and the display using something like this:

 

ImageJpeg ();

 

Thanks for the time and consideration! You guys are great!

Link to comment
https://forums.phpfreaks.com/topic/91019-hide-image-urlpath-from-user/
Share on other sites

what i sometimes do is create a page, lets say image.php,

and have the code go like this:

 

<?php

 

include('image.jpg');

 

?>

 

so when the user accesses the page,

it just displays a bunch of code,

but it still works when you do this:

 

<img src="image.php">

what i sometimes do is create a page, lets say image.php,

and have the code go like this:

 

<?php

 

include('image.jpg');

 

?>

 

so when the user accesses the page,

it just displays a bunch of code,

but it still works when you do this:

 

<img src="image.php">

 

Wait, how does that supposed to work?

 

I just tried it, I get a bunch of ASCII errors.

 

Thanks again!

<img src="index.php/images/disp.php?image=004">

 

the 'disp.php' file can fopen a file then fread it and then echo it out.  The file to fopen can even be in a directory that does not allow direct web access to the files.  You'll want to use the php header function  to set the content type header before echoing out the file contents:

 

header("Content-type: image/gif");
echo  file_get_contents("/directory/file4.gif");

 

this method should work for every image type, I have used it for jpg's and gif's.

i would advise to use this function sparingly as it will take up a lot of resources, especially with larger images. if the client wanted the image you cannot stop him.her from prntscrn'ing, in my view trying to hide the source file is a little pointless.

 

hope this helps,

  • 1 year later...

In Response to uniflare:

This is true, that the current script has no benefit. However, I dont see it using that much more resources than using your web servers mime handler, you are just transferring the mime handling to a php script.

 

but it can be the base for a more functional script, hit counter, hot-link prevention and so forth.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.