簡體   English   中英

HTML PHP表單文件上傳-在提交時顯示文件名並將文件發送到電子郵件

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

我有一個html表單,我有一個文件上傳按鈕-它可以將文件上傳到上傳文件夾。 我需要

  • 在提交時顯示上載的文件名。 應該將其添加到此塊中:

     <?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 } ?> 

目前,print_r顯示了該文件,但在混亂的數組中,我需要對其進行清理...

  • 提交此表單后,隨附的電子郵件便沒有附件。 在發送電子郵件的部分中,我所擁有的是:

     //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; } 

對於第一個問題,請使用$_FILES['datafile']['name']

對於第二個文件,將文件附加到電子郵件會有些棘手。 看一下這個教程 ,當我剛開始的時候它對我有很大幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM