用戶完成上傳多個文件後,我會顯示屏幕上傳的文件。我也試圖在電子郵件的正文中包含相同的列表。絕對一切正常,包括在屏幕上顯示每個文件,除了$ message_body只列出陣列中的最後一個文件名。有任何想法嗎??
<!DOCTYPE html>
<html>
<head>
<title>upload</title>
</head>
<body>
<?php
if(isset($_POST['ship-it']) AND $_POST['ship-it'] === "yes") {
$yesupload = $_POST['ship-it'];
preg_match("/yes/", "".$yesupload."");
for($i=0; $i<count($_FILES['tray']['name']); $i++) {
$filename = $_FILES['tray']['name'][$i];
$s_name = $_FILES['tray']['tmp_name'][$i];
move_uploaded_file($s_name, 'https://example.com/inbox/'.$filename.'');
}
$info = $_SERVER['HTTP_USER_AGENT'];
$message_body = "".$_POST["email"]." uploaded the file: ".$_FILES['tray']['name']."
https://example.com/inbox/".rawurlencode($filename)."
User Agent: ".$_POST["id"]." ".$info."";
$mail_options = [
'sender' => '[email protected]',
'to' => '[email protected]',
'subject' => 'new file sent',
'textBody' => $message_body
];
try {
$message = new Message($mail_options);
$message->send();
} catch (InvalidArgumentException $e) {
echo 'error: ';
}
echo "<p>All done. Here's what you sent:</p>";
for($i = 0; $i < count($_FILES['tray']['name']); $i++)
{
echo "<ul style='list-style-type:square'>
<li>{$_FILES['tray']['name'][$i]}</li>
</ul>";
}
}
?>
<form action="<?php echo $upload_url?>" method="post" enctype="multipart/form-data">
<p>Files to upload: </p> <br>
<input type="hidden" name="ship-it" value="yes">
<input type="hidden" name="id" value="<?php echo $_SERVER['REMOTE_ADDR']?>">
<input type="email" name="email" required="" autofocus placeholder="Your email address"><br><br>
<input type="file" multiple name="tray[]" required="">
<input type="submit" value="Upload"><br><br>
</form>
</body>
</html>
您遍歷'$ _FILES [「托盤」] [「名」]'當你告訴你在屏幕上的消息,但你不這樣做,當你建立你的郵件正文。 – jeroen 2014-11-04 21:00:40
1.似乎_https:// url不能在'move_uploaded_file'中。 2. preg_match的調用在那裏不清楚。 – Deadooshka 2014-11-04 21:36:05
^^^確切^^使用服務器路徑而不是URL。 – 2014-11-04 21:42:53