Do not access image by url

Asked

Viewed 106 times

2

How do I pass an image to the component img without the user being able to copy the url of the image and access the file by browser?

inserir a descrição da imagem aqui

<img src="https://meusite.com.br/assets/upload/galeria/89483adsd4r49939304.png"/>
<img src="<?php echo $url?>assets/upload/galeria/<?php echo $foto->imagem?>"/>
  • If the browser can open the signficia image that the user can also, even if you code the user can also take the coded code and decoficarlo, if you want to hide the original address of the image, could try htaccess;

  • you can open the file and present the Base64 as data:url this will not prevent the user from copying the image... but will not expose its address on the server that in case does not need to be in the structure accessible to the client.

  • Why do you want to hide the url of src for the user?

  • 1

    You are wanting the user not to be able to access the folder and see all the files in it ? (browsing directory)

  • 2

    @Icaromartins like that

  • You’re wearing apache2 ?

  • @Icaromartins yes I am using apache.

Show 2 more comments

1 answer

2


Disabling the Directory browsing of apache2, you can use one of the options below.

Option 1: Via command:

a2dismod autoindex

After that the apache2

/etc/init.d/apache restart

Option 2: Editing apache configuration file

Old location: Find your file httpd.conf usually in the path /etc/apache/httpd.conf (source of that information seems this outdated)

Most recent location: Search the site configuration file by default is 000-default.conf and is in the path /etc/apache2/sites-enabled/

Look for a line similar to the one shown below

Options Includes Indexes FollowSymLinks MultiViews

Remove the text Indexes as shown below
(if you do not have one of the items shown is not necessary to add, the important here and you take the Indexes)

Options Includes FollowSymLinks MultiViews

After that the apache2

/etc/init.d/apache restart

Option 3: only in a specific directory

Another method is to create a file .htaccess inside the folder you want to disable this Feature and put as content

Options -Indexes

Option 4: Create a file index.php or index.html

Placing an index.php or index.html file in the folder when the user tries to access the folder will fall within the index you created and not the apache automatic index.


[NOTE]: In case you want to hide the image path you can create a file to act as an image, simply upload the image data to a variable (such as using the function file_get_contents('imagem.png')) and use one of the examples in this reply

Sources: stackoverflow - EN

  • 1

    But he didn’t want to hide the address from the image of src="" ?

  • 2

    I guess he didn’t know how to express himself, so I asked question comment.

  • 2

    @Icaromartins worked with the Option 2. Only with . htaccess solved the problem. About the question I did less technical, because I would like to know what would be the options that could have to solve the problem and that’s exactly what you answered. Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.