Jump to content

Download File after Authentication


Alexandru_mbm

Recommended Posts

Hello to you all!

 

This is my first post on this big big forum! Nice one!

 

Let's go directly to the problem...

 

I have an website that has few informations about a process or a product.

In this page there is an PDF file that has the hole description and details about that process or product.

 

All i want is that the visitors to register into my website and after that thei can download any PDF file (or other) as much as thei want.

 

 

I have found some samples on the internet but is only for authentication not for download too.

 

Anyone can help me with this problem ? Please!!!

 

(sorry for my bad english)

Link to comment
https://forums.phpfreaks.com/topic/73120-download-file-after-authentication/
Share on other sites

you can link to the download as download.php?file=1 and then in that you can have:

 

$registered = $_SESSION['logged_in']?true:false; // replace with actual login sequence data
if(!$registered)
    die("message to be displayed if not registered");

$fileid = $_GET['file'];
switch($fileid)
{
case 1: $file = "somefile1.pdf"; break;
case 1: $file = "somefile2.pdf"; break; // ...etc
default: die("message if file does not exist"); break; // if file ID is not in switch
}
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($file));
header("Content-disposition: attachment; filename=\"".basename($file)."\"");
readfile($file);

(untested but should work)

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.