How to hide the physical path of the images

前端 未结 2 1313
清歌不尽
清歌不尽 2021-01-25 13:14

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

相关标签:
2条回答
  • 2021-01-25 13:57

    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

    0 讨论(0)
  • 2021-01-25 14:08

    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

    0 讨论(0)
提交回复
热议问题