I have to allow a user to download after he has submitted his USER data.
I've created three pages,
will display files available for download(catalogue_downloads.html)
will take in USER data (form_collecting.php)
will take user data validate it send it to an email address and redirect to downloads page (mail.php)
开发者_开发技巧The schema is so catalogue_downloads.html->form_collecting.php->mail.php->catalogue_downloads.html
I am able to redirect to catalogue_downloads but how can I make the user download the file he requested via PHP
Thank you
Regards
Vinoth
http://php.net/manual/en/function.readfile.php read the first part (forcing a download), you can read a file and then sending it to the user via the headers. Thus you don't have to give away your file structure (and perhaps even letting the file outside your website's root/public_html).
You can't feed the user multiple files, so unless you compress them server side in a single archive you have to show him the links to the files.
However, you're not limited to a link to the actual file, you can link to a "dowloader page" which feeds the user a single file when called so unauthorized users can't access the files (see PENDO's answer on how to do that).
you can user below code if needed..
$root = $_SERVER['DOCUMENT_ROOT']; $site = '';
$folder = "path where you want to store downloaded files";
$fullPath = $root.$folder.'/'.$_REQUEST['filenm'];
//$_REQUEST['filenm'] = file name which you want to download.
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower(html);
header("Content-type: application/".$ext);
header("Content-Transfer-Encoding: Binary");
header("Content-Disposition: attachment;filename=\"".$path_parts["basename"]."\"");
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
} } fclose ($fd); exit;
Thanks.
Here is the deal:
When redirecting from catalogue_downloads.html to form_collecting.php, give your catalog a unique ID and post it to form_collecting.php. Keep a hidden input field in your form which will keep the previously posted catalog ID. When the form is posted and validated start the process of mail.php. When mail is successful, read the catalog ID and redirect your user to the catalogue_downloads.html.
Hope this will help you out. Regards
精彩评论