Jump to content

[SOLVED] Random/Unique download link


XeroXer

Recommended Posts

Hi there!

I am making a download directory that demands that the user is logged in.
Got any idea on how to either randomize a download link for every user download or to make the exact file link never show.
Really need help with this and I haven't found a good system for this yet.
Link to comment
https://forums.phpfreaks.com/topic/31988-solved-randomunique-download-link/
Share on other sites

You can rewrite links in php

[code]
<?php
function  send_file($path,  $display)
{
        if  (!is_file($path)  or  connection_status()!=0)
                return(FALSE);

        header("Content-type:  unknown/unknown");
        header("Content-Disposition:    attachment;  filename=\"$display\"");
        header("Pragma:  public");
        header("Cache-control:  private");
        header("Content-transfer-encoding:  binary\n");
        header("Content-length:  ".(string)(filesize($path)));
        header("Expires:  0");
        header("Pragma:  no-cache");

        if  ($file  =  fopen($path,  'rb'))
        {
                while(!feof($file)  and  (connection_status()==0))
                {
                        print(fread($file,  1024*300));
                        flush();
                }
                $status  =  (connection_status()==0);
                fclose($file);
        }
        return($status);
}
$requested_file  =  ((  isset($_GET['file'])  )?($_GET['file']):  (''));

//  Fake  filename  =>  Real  Filename
$rewrite  =  array(
'Example.rar'=>'test/myrar.rar'
,'Tutorial.zip'=>'x401TPT.zip'
);

if(array_key_exists($requested_file,$rewrite))
{
        send_file($rewrite[$requested_file],$requested_file);
}
?>
[/code]

You can call this with

www.example.com/page.php?file=Example.rar

and Example.rar will download

But the file is in a folder called test, and the file is called myrar.rar

With a Little playing, you can do it different ways

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.