可以在php中隐藏图像的真实路径吗? [英] Hide real path of images in php is possible?

查看:65
本文介绍了可以在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!

这篇关于可以在php中隐藏图像的真实路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆