F
F
focusgroup2015-08-28 16:54:32
PHP
focusgroup, 2015-08-28 16:54:32

input file multiple. Script error?

Please help me. There is code below. You can select multiple files in a form. But why does only 1 attachment file come to the mail? php error? What is missing?

<form id="form_modal_mail" action="send.php" method="post" name="form1" enctype="multipart/form-data">
                                    <div class="form-group-mail">
                                        <input name="txtFormName" type="text" id="name" placeholder=" Имя">
                                    </div>
                                    <div class="form-group-mail">
                                        <input name="txtFormEmail" type="text" id="phone" placeholder=" Телефон" required>
                                    </div>
                                    <div class="form-group-attach-mail">
                                        <input name="fileAttach" id="attach" type="file" required multiple> 
                                    </div>
                                    <div class="form-group-mail">
                                    <textarea name="txtDescription" id="question" placeholder="Ваш вопрос"  maxlength="400"></textarea>
                                     </div>
                                    <div class="form-group-btn-footer">
                                        <button name="Submit" type="submit" id="btn_form">Отправить письмо</button>
                                    </div>
                </form>

send.php actual handler
<?  
$strTo = "[email protected]";
$strSubject = "Письмо с сайта!";
$strMessage = nl2br($_POST["txtDescription"]);  
  
//*** Uniqid Session ***//  
$strSid = md5(uniqid(time()));  
  
$strHeader = "";  
$strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";  
  
$strHeader .= "MIME-Version: 1.0\n";  
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";  
$strHeader .= "This is a multi-part message in MIME format.\n";  
  
$strHeader .= "--".$strSid."\n";  
$strHeader .= "Content-type: text/html; charset=utf-8\n";  
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";  
$strHeader .= $strMessage."\n\n";  
  
//*** Attachment ***//  
if($_FILES["fileAttach"]["name"] != "")  
{  
$strFilesName = $_FILES["fileAttach"]["name"];  
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));  
$strHeader .= "--".$strSid."\n";  
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";  
$strHeader .= "Content-Transfer-Encoding: base64\n";  
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";  
$strHeader .= $strContent."\n\n";  
}
  
$flgSend = @mail($strTo,$strSubject,null,$strHeader);  // @ = No Show Error //  
  
if($flgSend)  
{  
echo "";  
}  
else  
{  
echo "Возникла ошибка! Документы не загружены";  
}  
ini_set('short_open_tag', 'On');
header('Refresh: 3; URL=index.html');
?>
    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <title>Файл отправлен</title>
        <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
        <link rel="stylesheet" href="css/style.less" type="text/less">

    </head>

    <body>
    <script type="text/javascript">
    

            alert("Документы отправлены! Спасибо.");
      
      
        </script>
        <script src="assets/less/less.min.js"></script>
        <script type="text/javascript">
            setTimeout('location.replace("/index.html")', 1000);
            миллисекунд)
        </script>

    </body>

    </html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
magazovski, 2015-08-28
@focusgroup

<input name="fileAttach[]" id="attach" type="file" required multiple>

foreach($_FILES["fileAttach"]["name"] as $i => $strFilesName) {
    $tmp_name = $_FILES["fileAttach"]["tmp_name"][$i];
    ....
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question