未定义的索引错误

时间:2010-11-17 15:08:27

标签: php

我有一个PHP上传程序脚本,可以处理多个上传。该脚本运行良好但我在下面收到此错误:

Notice: Undefined index: uploadedFile in C:\wamp\www\setapro\rmc_manager.php on line 52

以下错误发生在以下一行:

$inFilesArray = ($_FILES['uploadedFile']['name']);

我试过做类似的事情:

if (!isset($_FILES['uploadedFile']['name'])){
$_FILES['uploadedFile']['name'] = '';
}

但它不起作用。我想对通知采取一些措施。任何建议,将不胜感激。感谢

编辑:我的部分内容

form action="rmc_manager.php" method="post" enctype="multipart/form-data"><input    type="hidden" name="MAX_FILE_SIZE" value="3000000" />

Please choose files to upload:<br />
<input name="uploadedFile[]" type="file" class="txt" /><br /> 
<input name="uploadedFile[]" type="file" class="txt" /><br />
<input type="submit" name="uploadfiles" value="Upload files" class="btn" />

PHP上传管理器:

if (isset($_POST['uploadfiles'])) {
$number_of_uploaded_files = 0;
$number_of_moved_files = 0;
$uploaded_files = array();
$upload_directory = dirname(__file__) . '/Uploads/';
for ($i = 0; $i < count($_FILES['uploadedFile']['name']); $i++) {
    if ($_FILES['uploadedFile']['name'][$i] != '') { //check if file field empty or not
        $number_of_uploaded_files++;
        $uploaded_files[] = $_FILES['uploadedFile']['name'][$i];
        //if (is_uploaded_file($_FILES['uploadedFile']['name'])){
        if (move_uploaded_file($_FILES['uploadedFile']['tmp_name'][$i], $upload_directory . $_FILES['uploadedFile']['name'][$i])) {
            $number_of_moved_files++;
        }

    }

}

}
echo "Number of files submitted $number_of_uploaded_files . <br/>";
echo "Number of successfully moved files $number_of_moved_files . <br/>";
echo "File Names are <br/>" . implode("<br/>", $uploaded_files);
echo "<br></br>";
echo "<p> Please find the processed GGAs with dates in the Setapro project folder</p>";

2 个答案:

答案 0 :(得分:0)

$_FILES['uploadedFile']之前测试$_FILES['uploadedFile']['name']

编辑:事实上,只需测试$_FILES['uploadedFile'] ^^

答案 1 :(得分:0)

在你这样做之前

$inFilesArray = ($_FILES['uploadedFile']['name']);
你应该使用php函数isset(...),

例如

if(isset($_FILES['uploadedFile']['name']))