hide a folder path when user downloads a file

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.

suppose my file is stored in

Read More
http://www.example.com/wp-content/example.folder/awesome.png

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.

Related posts

Leave a Reply

1 comment

  1. Example With PDF doc

    $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);
    

    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);