简体   繁体   中英

HTML PHP form file upload - display file name on submit and send file to email

I have an html form I have a file upload button - it works the file is uploaded to an upload folder. I need to

  • have the uploaded file name display on submit. It should be added to this block:

     <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?> <div id="sadhu"> <p class="general_site">First Name:<strong><?php echo $firstname;?></strong></p> <p class="general_site">Last Name:<strong><?php echo $lastname;?></strong></p> <p class="general_site">Email:<strong><?php echo $email;?></strong></p> <p class="general_site">Theme:<strong><?php echo $theme;?></strong></p> <p class="general_site">Type:<strong><?php echo $type;?></strong></p> <p class="general_site">Upload:<strong><?php print_r($_FILES['datafile']);?></strong></p> </div> <?php } ?> 

At the moment print_r shows the file but in a messy array I need to clean it up...

  • Once this form is submitted the email that comes though does not have the attached file. In the part that sends the email all I have is this:

     //If there is no error, send the email if(!isset($hasError)) { $emailTo = 'info@bgv.co.za'; //Put your own email address here $body = "First Name: $firstname \\n\\nLast Name: $lastname \\n\\nEmail: $email \\n\\nTheme: $theme \\n\\nType of Abstract: $type \\n\\nUpload: $datafile \\n\\n"; $headers = 'From: My Site <'.$emailTo.'>' . "\\r\\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } 

for your first question use $_FILES['datafile']['name']

for the second one, attaching files to an email is a bit more tricky. have a look at this tutorial , it helped me a lot when i was starting out

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM