脚本有效,但只发送一个附件。我似乎无法弄清楚我做错了什么。它会发送第一个附件$ userfile ['name'] [0],但不会发送$ userfile ['name'] [1]
$i = 0;
foreach($_FILES as $userfile){
$tmp_name = $userfile['tmp_name'][$i];
$type = $userfile['type'][$i];
$name = $userfile['name'][$i];
$size = $userfile['size'][$i];
$i++;
}
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multipart/form-data" name="form1">
<input type="file" name="file[]" multiple />
原始代码来自此处:How to attach two or multiple files and send mail in PHP
答案 0 :(得分:1)
将您的文件名更改为userfile [],然后应该是这样的:
应该是这样的:
$count_uploaded_files = count( $_FILES['userfile']['name'] );
for( $i = 0; $i < $count_uploaded_files; $i++ )
{
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
$type = $_FILES['userfile']['type'][$i];
$name = $_FILES['userfile']['name'][$i];
$size = $_FILES['userfile']['size'][$i];
// Do whatever you want with $temp_name, $type, $name, and $size ...
}
但是如果你想留在文件[]。然后是这样的:
$count_uploaded_files = count( $_FILES['file']['name'] );
for( $i = 0; $i < $count_uploaded_files; $i++ )
{
$tmp_name = $_FILES['file']['tmp_name'][$i];
$type = $_FILES['file']['type'][$i];
$name = $_FILES['file']['name'][$i];
$size = $_FILES['file']['size'][$i];
// Do whatever you want with $temp_name, $type, $name, and $size ...
}