nashed_uk Posted July 7, 2006 Share Posted July 7, 2006 hello, I've been trying to solve this for a couple of days now, but i'm not getting anywhere, hope you can help.I have a website with a page where you fill in a form and select a radio button which is assigned to a file which can then be downloaded by clicking on a download button on the next page after the form has been submitted. (it would be nice to start the download at the same time the form is submitted, but i'm not that clever.)Now the problem come when the file is download. It downloads fine and all look good untill you go to open it. Its a PDF file thats downloaded, which is fine, but Adobe Acrobat Reader says that it is not supported or the file have been corrupted. Looking closser at the file its turns out to have no size to it, its 0kb. Or of the file I have available are at least 8kb so I know somthing isn't quite happening right.Heres my for for the download section.<?phpsession_start();$files = array("21_Ways_BarRunners_CounterMats.pdf","21_Ways_FloorMats_CarpetTiles.pdf","Money_on_the_Floor_Report.pdf","Marketing_Week_Report.pdf","7_Key_Questions_for_Your_Supplier.pdf");$download = ($_SESSION["download"]);$folder = "/home/mouselist/public_html/mysharedaccounts/decomatslist/download";$downloadfile = $folder."/".$files[$download];if(file_exists($downloadfile)){ //echo $downloadfile; //echo "the file exists"; header("Content-type: application/pdf"); header("Content-Disposition: attachment; filename=\"{$files[$download]}\""); readfile($downloadFile); exit(); }else { header("location: ../formNoFile.htm");}?>and heres the code for the form processing<?phpsession_start();$files = array("21_Ways_BarRunners_CounterMats.pdf","21_Ways_FloorMats_CarpetTiles.pdf","Money_on_the_Floor_Report.pdf","Marketing_Week_Report.pdf","7_Key_Questions_for_Your_Supplier.pdf");$name = validate_plain_text($_POST["name"]);$company = validate_plain_text($_POST["company"]);$email = isValidEmail($_POST["email"]);$postcode = validate_plain_text($_POST["postcode"]);$download = ($_POST["download"]);if($name==false){ header("location: ../formError.htm"); exit();}if($company==false){ header("location: ../formError.htm"); exit();}if($email==false){ header("location: ../formError.htm"); exit();}$from="From: username@domain.com\n". "X-Mailer: CMS Version 1.0\n". "Reply-To: username@domain.com\r\n\r\n";$body = "User Details:\r\n". "Name = $name\r\n". "JobTitle = {$_POST["jobTitle"]}\r\n". "Company = $company\r\n". "Email Address = $email\r\n\r\n". "Website = {$_POST["website"]}\r\n". "Address = {$_POST["address"]}\r\n". "city = {$_POST["city"]}\r\n". "postcode = $postcode\r\n". "Tel = {$_POST["tel"]}\r\n". "Download = {$files[$download]}\r\n"; mail("username@domain.com","DecomatCompany Free Resources",$body,$from);mail("$email","DecomatCompany Free Resources","Thankyou for taking the time to download one of our Free resources\r\n\r\nThe Decomat Company" ,$from);header("location: ../formDownloadThankyou.htm");$_SESSION["download"]=$_POST["download"];/*$folder = "/home/rob/public_html/decomatcompany/download";$downloadfile = $folder."/".$files[$download];if(file_exists($downloadfile)){ //echo $downloadfile; //echo "the file exists"; header("Content-type: application/pdf"); header("Content-Disposition: attachment; filename=\"{$files[$download]}\""); readfile($downloadFile); exit;}else { header("location: ../formNoFile.htm");}*/function validate_plain_text($data){ //check for empty data if (trim($data)==='') { return ''; } //strip specialchars $data=htmlentities($data); //test only for plain text and punctuation . , ' : ; ( ) ? ! $pattern="[&%\^@#<>]"; if (ereg($pattern,$data)) { //we have found illegal chars return false; } else { return $data; } } function isValidEmail($email){ $result = false; //process email to check it is seems in an OK format //check for an empty email address if (trim($email)!='') { $pattern='/^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i'; if (preg_match($pattern,$email)>0) { $result = $email; } } return $result;}?>thankyou so much for any helpRob Quote Link to comment https://forums.phpfreaks.com/topic/13948-php-help-download-0kb/ Share on other sites More sharing options...
Daniel0 Posted July 7, 2006 Share Posted July 7, 2006 Take a look at [url=http://www.phpfreaks.com/forums/index.php/topic,95433.0.html]this topic[/url]... I believe that solves your problem. Quote Link to comment https://forums.phpfreaks.com/topic/13948-php-help-download-0kb/#findComment-54415 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.