Force users to fill out form before file download

Reply

Join Date: Jan 2008
Posts: 2
Reputation: Markstein is an unknown quantity at this point 
Solved Threads: 0
Markstein Markstein is offline Offline
Newbie Poster

Force users to fill out form before file download

 
-1
  #1
Oct 8th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,068
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 137
ardav's Avatar
ardav ardav is online now Online
Veteran Poster
 
-2
  #2
Oct 8th, 2009
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...s_to_restrict/

For some reason Content-Disposition header is frowned upon.
Happy Humbugging Christmas
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2
Reputation: Markstein is an unknown quantity at this point 
Solved Threads: 0
Markstein Markstein is offline Offline
Newbie Poster
 
-1
  #3
Oct 8th, 2009
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
Last edited by Markstein; Oct 8th, 2009 at 6:53 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,385
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 167
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso
 
1
  #4
Oct 8th, 2009
Where the file is accessed by
  1. <a href='download.php?file=thisfile.pdf'>download Thisfile.pdf</a>

mysql
  1. <?php /*download.php*/
  2. If (!$_POST['file']='') {
  3. /* validate $_POST any amount of form validation this is just an exercise
  4. or die('invalid information'); */
  5. $con=mysql_connect("server","user","password");
  6. if (!$con) { die('Could not connect: '.mysql_error()); }
  7. mysql_select_db("my_db", $con);
  8. mysql_query("INSERT INTO downloads (FirstName, LastName, Company, email, telephone, file) VALUES ('$_POST['Firstname']', '$_POST['Lastname']', '$_POST['Company']', '$_POST['email']', '$_POST[telephone]', '$_POST['file']')");
  9. $path=''; //full path outside the root to downloadable files
  10. header("Content-disposition: attachment; filename=$_POST['file']");
  11. header('Content-type: application/pdf;');
  12. readfile("$path$_POST['file']"); }
  13. else {echo '<form action="'.$_SERVER['php_self'].'" method="post">';
  14. .'<input name="file" type="hidden" value="'.$file.'">';
  15. .'Firstname ?<input name="Firstname" type="text"><br>';
  16. .'lastname ?<input name="Lastname" type="text"><br>';
  17. .'Company ?<input name="Company" type="text"><br>';
  18. .'email ?<input name="email" type="text"><br>';
  19. .'telephone ?<input name="telephone" type="text"><br>';
  20. .'<input name="go" type="submit" Value="Download file"></form>'; }
  21. ?>
csv text file
  1. <?php <?php /*download.php*/
  2. If (!$_POST['file']='') {
  3. /* validate $_POST any amount of form validation this is just an exercise
  4. or die('invalid information'); */
  5. $file = "./logfiles/logfile.csv";// define the text file, named as .csv excell can open it.
  6. $fp = fopen($file, "a+");//open the text file for writing.
  7. fputs ($fp, "$_POST['Firstname'],$_POST['Lastname'],$_POST['Company'],$_POST['email'],$_POST[telephone],$_POST['file']\n");
  8. fclose($fp);
  9. $path=''; //full path outside the root to downloadable files
  10. header("Content-disposition: attachment; filename=$_POST['file']");
  11. header('Content-type: application/pdf;');
  12. readfile("$path$_POST['file']"); }
  13. else {echo '<form action="'.$_SERVER['php_self'].'" method="post">';
  14. .'<input name="file" type="hidden" value="'.$file.'">';
  15. .'Firstname ?<input name="Firstname" type="text"><br>';
  16. .'lastname ?<input name="Lastname" type="text"><br>';
  17. .'Company ?<input name="Company" type="text"><br>';
  18. .'email ?<input name="email" type="text"><br>';
  19. .'telephone ?<input name="telephone" type="text"><br>';
  20. .'<input name="go" type="submit" Value="Download file"></form>'; }
  21. ?>
Last edited by almostbob; Oct 8th, 2009 at 8:03 pm.
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
-1
  #5
Oct 9th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC