php - .htaccess file stop access of pic with direct URL
I have a website in php and CodeIgniter where user upload their profile pic and profile pic is stored in folder with name pic_uid.jpg .
And then my script load pic from same folder.
I want to stop direct access of pic using.htaccess
file.
like if pic path is
http://localhost/myweb/uploads/users/pic_19.jpg
If some one type this direct path, he will not get access to pic but when my script call this pic he can get access and show the pic.
I have tried many options but when i stop access to directory, my script also can't load pic.
How to achieve this ?
Thanks
Answer
Solution:
You can do something like this. Have a directory say,
secured
. And inside that directory, place this.htaccess
:And now, store all your image files there:
And in your PHP Script, use this proxy:
To reiterate what all I have done, I created a repo here at Cloud9. In that, I have got these files:
And the each file has like this:
insecure.php
secured/.htaccess
secured/hello.txt
Demos
Answer
Solution:
For stop access of pic with direct URL
Use URI of codeiginiter copy this code in your routes.php
This code blocked all url accessing a folder uploads/users