可以在php中隐藏图像的真实路径吗?

问题描述:

在我的网络服务器中,我有这些文件.我不希望用户找到我的p1.jpg"和p2.jpg"的真实路径.

In my web server, I have these files. I don't want user to find out my real path to "p1.jpg" and "p2.jpg".

当我在index.php"中显示p1.jpg"时,如何隐藏原始路径/images/p1jpg"像这样的/photo/p1.jpg".可能吗?

When i show "p1.jpg" in "index.php", how to hide original path "/images/p1jpg" to something like this "/photo/p1.jpg". Is it possible?

在我看来,这有两个部分.

So as I see it, there are two parts to this.

1) 隐藏images/的内容

1) Make it so the contents of images/ is hidden

2) 使一个人可以访问 photos/somefile.jpg 并让服务器提供 images/somefile.jpg

2) Make it so a person can access photos/somefile.jpg and have the server serve images/somefile.jpg

1) 隐藏图片内容/

在images/中创建一个.htaccess文件并将以下内容放入其中

Create a .htaccess file in images/ and put the following in it

Order allow,deny
Deny from all

2) 提供文件

在照片/中创建一个.htaccess文件并将以下内容放入其中

Create a .htaccess file in the photos/ and put the following in it

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_.-]+).jpg$ photo.php?image_name=$1

并在photos/目录下创建php文件photo.php

And create the php file photo.php in the photos/ directory

<?php

if(isset($_GET['image_name'])){

  if(file_exists("../images/" . $_GET['image_name'].".jpg")){

      header('Content-Type: image/jpg');
      readfile("../images/" . $_GET['image_name'].".jpg");
  }

}

我正在做那个盲目的,但会在一秒钟内测试!

I'm doing that blind, but will test in a sec!