Jump to content

Recommended Posts

Hi php legends,      Please help me.........

            I am creating my own site with the help of php.

       

            I want to create a download link. The users can download from that. But they should not get the url by right clicking on the link.

 

          The url should not be updated on the address bar because they will get the url from address bar. Kindly help me with the corresponding php script.

 

 

Thanks in advance

John

This works for me:

 

$path = "/path/to/file/on/server/file.zip";

$mm_type="application/x-zip-compressed"; // modify accordingly to the file type of $path

header("Content-Description: File Transfer");

header("Content-Type: " . $mm_type);

header('Content-Disposition: attachment; filename="' . basename($path) . '"');

header('Content-Transfer-Encoding: binary');

header("Expires: 0");

header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

header('Pragma: public');

header("Content-Length: " . (string)(filesize($path)) );

header("Cache-Control: private");

readfile($path); // outputs the content of the file

@dougjohnson how does that answer his question on

 

shouldn't be able to get the url

 

Since you only provide him the code on how to download the file.

 

@OP You can't hide the URL since the download client needs a location to read the file from. If you want to hide the URL to avoid people downloading from the direct link. You can create a token that lasts for one hour so that they need a valid token in order to dowload from it. Combine that with checking the IP-address of the download and the User-Agent and the chance becomes really small multiple people are downloading from one and the same URL.

 

This isn't a 100% guarantee but about 99.8% give or take.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.