如何隐藏实际的下载文件夹位置 [英] how to hide the actual download folder location

查看:234
本文介绍了如何隐藏实际的下载文件夹位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要隐藏的下载文件夹的位置,这样,当用户下载他看不到的位置的文件。为此,我认为它可以通过的.htaccess做,但如何做到这一点?而且我们可以做到这一点,PHP?如果我们能那么如何做到这一点?

I want to hide the downloading folder location so when the user download the file he can not see the location. for that i think it can be done by .htaccess but how to do this ? and can we do this by php ? if we can then how to do this ?

推荐答案

这是我如何做到这一点在PHP中:

This is how I do it in PHP:

<?php
$fakeFileName= "fakeFileName.zip";
$realFileName = "realFileName.zip";

$file = "downloadFolder/".$realFileName;
$fp = fopen($file, 'rb');

header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$fakeFileName");
header("Content-Length: " . filesize($file));
fpassthru($fp);
?>

和把一个名为的.htaccess 文件到您的下载文件夹中,只有内容:

and put a file named .htaccess into your download folder with only the contents:

deny from all

我改变℃的一点$ C $。首先,当我说假的文件名和真实的文件名,假文件名是名称的下载器会下载文件,其中真正的文件名是在下载文件夹服务器上的实际文件名。

I changed the code a little. First when I say fake file name and real file name, the fake filename is the name that the downloader will download the file as, where the real filename is the name of the actual file in the download folder on your server.

另外,我检查,以确保用户登录并能够下载该文件。如果他选择要下载的文件,一个PHP文件被称为在新标签页(从上面下载code),然后在文件的最后,我也行:

Also, I check to make sure the user is logged in and is able to download the file. If he chooses to download the file, a PHP file is called in a new tab (with the download code from above), then at the end of the file I have the line:

exit;

所以,当他点击下载链接,空白页弹出一个新的标签很快,然后迅速离开,并开始下载。

So when he clicks on the download link, a blank page pops up in a new tab quickly, then quickly exits and the download begins.

编辑:下载链接看起来是这样的:

The download link looks something like this:

<a href="simpleDown.php?id=<?php echo $_GET['id']; ?>" target="_blank">Download!</a>

其中, ID 是下载的数据库中的 ID ,并在上面我找到下载脚本与 ID输入,然后获取它的实际文件名和伪造文件名。你可以做到这一点没有数据库,但。

Where id is the id of the download in the database, and in the download script from above I find the entry with that id, then get its real file name and the fake file name. You can do this without the database though.

这篇关于如何隐藏实际的下载文件夹位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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