| | |
Force users to fill out form before file download
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2008
Posts: 2
Reputation:
Solved Threads: 0
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
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
-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.
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
•
•
Join Date: Jan 2008
Posts: 2
Reputation:
Solved Threads: 0
-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
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.
1
#4 Oct 8th, 2009
Where the file is accessed by
mysql csv text file
html Syntax (Toggle Plain Text)
<a href='download.php?file=thisfile.pdf'>download Thisfile.pdf</a>
mysql
php Syntax (Toggle Plain Text)
<?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>'; } ?>
php Syntax (Toggle Plain Text)
<?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>'; } ?>
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
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
![]() |
Similar Threads
- File Download problem (PHP)
- File Download Dialog Box(ASP) (ASP)
- system command not working in C functions.pls help (C)
- File Download Dialog Box(ASP) (ASP)
- IE; Getting file download box when attempting to access a particular web page (Web Browsers)
- File Download - Security Warning - Win XP (ASP.NET)
- help with writing CGI!! (Perl)
Other Threads in the PHP Forum
- Previous Thread: resize help
- Next Thread: How to Import excel data to mysql database?
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error fcc file files folder form forms function functions google howtowriteathesis href htaccess html image images include insert integration ip java javascript joomla ldap limit link login loop mail menu methods mlm mod_rewrite multiple multipletables mysql oop open parse paypal pdf php problem query radio random recursion regex remote script search server sessions sms soap source space speed sql structure syntax system table template tutorial update upload url validation validator variable video web xml youtube






