假设您的 HTML 代码中有
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="myFile1" />
<input type="file" name="myFile2" />
....
...// other input and your submit input
</form>
你的$_FILES
遗嘱结构是
Array
(
[myFile1] => Array
(
[name] => XXX
[type] => XXX
[tmp_name] => XXX
[error] => UPLOAD_ERR_OK (= 0)
[size] => XXXX
)
[myFile2] => Array
(
[name] => XXXX
[type] => XXXX
[tmp_name] => XXXX
[error] => UPLOAD_ERR_OK
[size] => XXXX
)
etc..
)
然后你可以做
// Loop on each entry of $_FILES
foreach($_FILES as $nameOfInputFile => $fileStructure) {
// Check the error status first, skip the file if an error occured
if ($fileStructure['error'] != UPLOAD_ERR_OK)
continue;
// $fileStructure contain the current file data
if(move_uploaded_file($fileStructure['tmp_name'],"test/" . $fileStructure['name']))
{
mysqli_query($db,"INSERT INTO files VALUES('" . $_POST['draft'] . "','$name','" . $fileStructure['size'] . "')");
}
}
注意:当您发布文件时,您的草稿值应使用$_POST