Hello,

I need to have users fill out a form before they are granted to download any given file to generate sales leads. I do have a script which was custom made but am having some issues with it.

I am wondering if anyone knows of a service (or script) that does this. I am baffled on my long search on Google that I haven't found anything like this!

Thank you for any suggestions!

Mark

Member Avatar for diafol

Are you talking about a login form? What's the model you're looking for? The complexity/access rights/file persistence may determine the solution that will fit your needs.

Redirects are a relatively simple method, which only occur if form data is verified. However this simple solution may not be suitable if you want to 'cloak' the origin of the folder/file.

Giving the filename an obscure name (e.g. a hashed name) can deter users from guessing other filenames from the same folder.

I'm sure there are loads of other solutions to this; some of them extremely sophisticated - however, these may an overkill.

I came across a discussion here:

http://www.reddit.com/r/PHP/comments/9nazh/ask_php_recommendations_on_methods_to_restrict/

For some reason Content-Disposition header is frowned upon.

Hey Ardav thanks for the response!

Basically what I have is some whitepapers and brochures for people (the public) to download. Basically before they are allowed to download a file they must fill out a form which asks them for their name, company, email, phone number etc. The information is stored in a database. This way I know who is downloading what file and gain potential sales leads.

Once they fill out the form they are redirected to a "thankyou" page which prompts a save as dialog and dishes out the file.

If they wish to download another file they repeat the process.

I have the files outside of the public root so they are not directly accessible.

I'm just wondering if there are any scripts out there that accomplish this or possibly an online service. Honestly I am shocked that I haven't been able to find a script that does this for a non-membership site.

Have you heard of such a script?

Thanks a lot,

Mark

Where the file is accessed by

<a href='download.php?file=thisfile.pdf'>download Thisfile.pdf</a>

mysql

<?php /*download.php*/
If (!$_POST['file']='') {
/* validate $_POST  any amount of form validation this is just an exercise
or die('invalid information'); */
$con=mysql_connect("server","user","password");
if (!$con) { die('Could not connect: '.mysql_error()); }
mysql_select_db("my_db", $con);
mysql_query("INSERT INTO downloads (FirstName, LastName, Company, email, telephone, file) VALUES ('$_POST['Firstname']', '$_POST['Lastname']', '$_POST['Company']', '$_POST['email']', '$_POST[telephone]', '$_POST['file']')");
$path=''; //full path outside the root to downloadable files
header("Content-disposition: attachment; filename=$_POST['file']");
header('Content-type: application/pdf;');
readfile("$path$_POST['file']"); }
else {echo '<form action="'.$_SERVER['php_self'].'" method="post">';
.'<input name="file" type="hidden" value="'.$file.'">';
.'Firstname ?<input name="Firstname" type="text"><br>';
.'lastname ?<input name="Lastname" type="text"><br>';
.'Company ?<input name="Company" type="text"><br>';
.'email ?<input name="email" type="text"><br>';
.'telephone ?<input name="telephone" type="text"><br>';
.'<input name="go" type="submit" Value="Download file"></form>'; }
?>

csv text file

<?php <?php /*download.php*/
If (!$_POST['file']='') {
/* validate $_POST  any amount of form validation this is just an exercise
or die('invalid information'); */
$file = "./logfiles/logfile.csv";// define the text file, named as .csv excell can open it.
$fp = fopen($file, "a+");//open the text file for writing.
fputs ($fp, "$_POST['Firstname'],$_POST['Lastname'],$_POST['Company'],$_POST['email'],$_POST[telephone],$_POST['file']\n");
fclose($fp);
$path=''; //full path outside the root to downloadable files
header("Content-disposition: attachment; filename=$_POST['file']");
header('Content-type: application/pdf;');
readfile("$path$_POST['file']"); }
else {echo '<form action="'.$_SERVER['php_self'].'" method="post">';
.'<input name="file" type="hidden" value="'.$file.'">';
.'Firstname ?<input name="Firstname" type="text"><br>';
.'lastname ?<input name="Lastname" type="text"><br>';
.'Company ?<input name="Company" type="text"><br>';
.'email ?<input name="email" type="text"><br>';
.'telephone ?<input name="telephone" type="text"><br>';
.'<input name="go" type="submit" Value="Download file"></form>'; }
?>
commented: Nice one +3

The file download form the server to the client machine will be done by the php, but before that restricting the user in some way or the client side validation will help to achieve what you want exactly with the javascript.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.