我有上傳單個文件和工作正常的情況如下:PHP多文件上傳不處理
<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";
}
?>
當我的Adpat此接受上傳多個文件,它似乎沒有工作。我沒有得到任何錯誤/警告,所以我完全難住。這裏是我的多個文件上傳代碼:
<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";
}
?>
有什麼建議可能是錯的?
'$ _FILES [ 「文件」]'是不一樣的'NAME =「userfile的[] 「' – TiMESPLiNTER
將你的'error_reporting'和'display_errors'設置爲明智的開發級別......這樣PHP就可以告訴你這樣的東西! – CBroe