简体   繁体   English

使用PHP隐藏HTML上的图像源

[英]Hide image source on HTML using PHP

In order to hide my images directory, so that the user doesn't know where the images are stored, how can I implement something like this? 为了隐藏我的图像目录,以便用户不知道图像的存储位置,我该如何实现这样的功能?

<img src="https://photos-1.dropbox.com/t/0/AADkpdIqLbXdAFgmjGbdsKa_InYsOtfwuekNtOyuHgmh3g/10/5642407/jpeg/32x32/6/_/1/2/Pensive%20Parakeet.jpg/HM183nQwcIFtc1PrTIOCRe4rIUK8wBaWKcgqD-g2Ma8?size=32bf&amp;prep_size=1280x960" draggable="true" alt="Pensive Parakeet.jpg" class="sprite sprite_web s_web_page_white_picture_32 icon thumbnail">

Where the source: https://photos-1.dropbox.com/t/0/AADkpdIqLbXdAFgmjGbdsKa_InYsOtfwuekNtOyuHgmh3g/10/5642407/jpeg/32x32/6/_/1/2/Pensive%20Parakeet.jpg/HM183nQwcIFtc1PrTIOCRe4rIUK8wBaWKcgqD-g2Ma8?size=32bf&prep_size=1280x960 来源在哪里: https : //photos-1.dropbox.com/t/0/AADkpdIqLbXdAFgmjGbdsKa_InYsOtfwuekNtOyuHgmh3g/10/5642407/jpeg/32x32/6/_/1/2/Pensive%20Parakeet.jpg/HM183nQWcCcTc1Pr4K 32bf&prep_size = 1280x960

renders the image without any problem. 渲染图像没有任何问题。

This type of functionality is typically implemented via a RewriteRule in your vhost or .htaccess file and some sort of image processing function. 通常通过vhost或.htaccess文件中的RewriteRule和某种图像处理功能来实现这种功能。 For example, you can put something like this in an .htaccess file in, say, the /t directory off of your document root: 例如,您可以将这样的内容放在文档根目录下的/ t目录中的.htaccess文件中:

RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

This will transparently redirect all calls behind the scenes to, for example (if placed in your /t directory), /t/0/foo/bar/stuff to /t/index.php/0/foo/bar/stuff . 这会将所有后台调用透明地重定向到(例如,如果放置在/ t目录中) /t/0/foo/bar/stuff/t/index.php/0/foo/bar/stuff Assuming you have an index.php file in that directory, you can then process all of the stuff in the URL it gets by parsing $_SERVER['REQUEST_URI'] or $_SERVER['PATH_INFO'] to figure out exactly what to return. 假设您在该目录中有一个index.php文件,则可以通过解析$_SERVER['REQUEST_URI']$_SERVER['PATH_INFO']找出返回的内容,来处理URL中的所有内容。

If you have images saved in an alternate location, you can return them by doing whatever munging you want to do with them and pushing them out to the browser using imagepng() or imagejpg() . 如果您将图像保存在其他位置,则可以通过做任何想做的事来返回它们,并使用imagepng()imagejpg()将它们推出到浏览器中。 See the example on one of those pages for how to do this. 有关如何执行此操作, 请参阅这些页面之一上的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM