ユーザーが1つのファイルをアップロードできるフォームを使用していますが、4つのファイルをアップロードできるようにしようとしています。私は例の負荷をしようとしたファイルは私の電子メールに送信されます。この単一の添付ファイルのアップロード以外の仕事に何かを得ることに何の運を持っていなかった:複数の添付ファイルを作成する
HTML:
<form enctype="multipart/form-data" action="send_attachments_email.php" method="post">
<label for="message">Message</label> <textarea name="message" id="message" cols="20" rows="8"></textarea>
<label for="file">File</label> <input type="file" name="file" id="file">
<input type="submit" name="submit" id="submit" value="send">
</form>
PHP:
<?php
if(isset($_POST['submit']))
{
//The form has been submitted, prep a nice thank you message
$output = '<h1>Thanks for your file and message!</h1>';
//Set the form flag to no display (cheap way!)
$flags = 'style="display:none;"';
//Deal with the email
$to = '[email protected]';
$subject = 'a file for you';
$message = strip_tags($_POST['message']);
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
$filename = $_FILES['file']['name'];
$boundary =md5(date('r', time()));
$headers = "From: [email protected]\r\nReply-To: [email protected]";
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
$message="This is a multi-part message in MIME format.
--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
--_2_$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit
$message
--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--_1_$boundary--";
mail($to, $subject, $message, $headers);
}
?>
ファイルを配列にする必要がありますが、PHPはまだ動作しますか?それとも最善の方法は何ですか?
ありがとうございます!
私は、アレイ持つようにPHPを変更しようとしている: '$ファイル名= $ _FILES [ '[]ファイルを'] [ '名前'] [ '0']; \t \t $ filename1 = $ _FILES ['file []'] ['name'] ['1']; \t \t $ filename2 = $ _FILES ['file []'] ['name'] ['2']; \t \t $ filename3 = $ _FILES ['file []'] ['name'] ['3']; 'これは何も送信しません。 – Bethfiander
複数のファイルを選択できますか? – TheTom
お返事ありがとうございます。はい、私はWebページ上で複数のファイルを選択することができますが、私がsendを押すと、私は空白の電子メールを受け取ります。貼り付けたコードを使用すると、1枚の写真で電子メールを受け取ることができますが、配列を追加しようとすると空白が表示されます。 – Bethfiander