“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

后端 未结 28 927
盖世英雄少女心
盖世英雄少女心 2021-01-24 14:18

I\'m running a PHP script and continue to receive errors like:

Notice: Undefined variable: my_variable_name in C:\\wamp\\www\\mypath\\index.php on line 10

28条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 15:00

    When dealing with files, a proper enctype and a POST method are required, which will trigger an undefined index notice if either are not included in the form.

    The manual states the following basic syntax:

    HTML

    
    
    Send this file:

    PHP

    ';
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
        echo "File is valid, and was successfully uploaded.\n";
    } else {
        echo "Possible file upload attack!\n";
    }
    
    echo 'Here is some more debugging info:';
    print_r($_FILES);
    
    print "
    "; ?>

    Reference:

    • http://php.net/manual/en/features.file-upload.post-method.php

提交回复
热议问题