隐藏的文件夹路径,当用户下载文件文件夹、路径、文件、用户

2023-09-02 00:28:04 作者:誓言抵挡不过我们的善变、

我用的词preSS为我的网站,并有我的文件夹中的一些墙纸,我提供下载。但我不希望用户知道文件的确切文件位置。由于没有为下载订阅。

I am using wordpress for my website and there are some wallpapers in my folder which i provide for download . But i dont want users to know the exact file location of folder . As there is a subscription for the download.

假设我的文件存储在

https://m.xsw88.com/allimgs/daicuo/20230902/96.png

现在如何隐藏文件夹名称 example.folder 和使用假名字,这dosent显示出来,同时下载。真的需要这一个很大的帮助。任何人都可以建议我一个很好的方法。我尝试了一些字preSS的插件,但没有这方面的帮助。

Now how to hide the folder name example.folder and use any fake name, That dosent shows up while downloading . Really need a big help on this. can anyone suggest me a good method. I tried some wordpress plugins , but no help on this.

推荐答案

例使用PDF文档

$nameOld = "/public_html/wp-content/example.folder/oldnme.pdf";
$nameNew = "newName.pdf" ;
header("Content-Transfer-Encoding: binary");
header('Content-type: application/pdf');
header("Content-disposition: attachment; filename=$nameNew"); //
readfile($nameOld);

修改 证明概念的使用的download.php?IMG =花不带扩展名和显示在图像的成像系统名称

Edit Prove of Concept for your image system using download.php?img=flower without the extension and flower show be the image name

$directory = "/public_html/wp-content/example.folder/";
$types = array("jpg","gif","png");
$ext = null;

if (! isset($_GET['img'])) {
    die("Invalid URL");
}

$nameOld = filter_var($_GET['img'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW);
$nameNew = uniqid(basename($nameOld));

// File the file
foreach ( $types as $type ) {
    if (is_file($nameOld . "." . $type)) {
        $ext = $type;
        break;
    }
}

if ($ext == null) {
    die("Sorry Image Not Found");
}
$nameOld .= "." . $ext;
$type = image_type_to_mime_type(exif_imagetype($nameOld));

header("Content-Transfer-Encoding: binary");
header('Content-type: ' . $type);
header("Content-disposition: attachment; filename=$nameNew"); //
readfile($nameOld);