How to hide the physical path of the images

这一生的挚爱 提交于 2019-12-31 04:10:52

问题


In my application i display the image of user by giving the physical path of the directories like http://www.example.com/user_images/abcdefghijk.jpg

But i dont want to expose this physical path to the external users to access the direct files. I want to implement the image retrieval as per the gravtar type image display. How we can do that?


回答1:


In PHP you can use GD library to read the image. So the only way you need to create a image.php file & use the following code,

<?php
$imagepath="your image physical path";

$image=imagecreatefromjpeg($imagepath);

header('Content-Type: image/jpeg');
imagejpeg($image);
?>

this is for jpg image for all other images you can use different functions fo GD library.

So Gravtar.com uses the above way to display the image :)

In ROR you can use Rmagick gem to read the image & display the image with the same way.

Thanks




回答2:


in php you can save a variable in session and append it to image's path like

<img src="php_function.php?token=1234" />

and in php file get the image reading from session its actual path and return the content by file_get_contents

here is the source http://hashmode.com/hide-image-path-php/9



来源:https://stackoverflow.com/questions/12371032/how-to-hide-the-physical-path-of-the-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!