我有以下上传单个文件并且工作正常:
<form enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="512000" />
<input name="userfile" type="file" />
<input type="submit" value="Upload" />
</form>
<?php
$uploaddir = $campaign['upload_dir'].'/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File has been successfully uploaded.\n";
} else {
echo "Upload failed";
}
?>
当我调整它以接受多个文件进行上传时,它似乎不起作用。我没有收到任何错误/警告,所以我完全被难住了。这是我的多文件上传代码:
<form enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="512000" />
<input name="userfile[]" type="file" multiple />
<input type="submit" value="Upload" />
</form>
<?php
$uploaddir = $campaign['upload_dir'].'/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name'][$key]);
foreach ($_FILES["userfile"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$name = $_FILES["userfile"]["name"][$key];
move_uploaded_file( $_FILES["userfile"]["tmp_name"][$key], $uploadfile);
{
echo "File has been successfully uploaded.\n";
} else {
echo "Upload failed";
}
?>
关于什么可能是错的任何建议?