PHP Undefined index error $_FILES?

后端 未结 4 537
暗喜
暗喜 2020-11-30 14:36

I am new to PHP and am following a tutorial on YouTube. I have everything working in this file, except for the file uploading, any help would be appreciated. Here is the e

相关标签:
4条回答
  • 2020-11-30 14:47

    For uploading files, you must use the enctype in form tag.

    <form enctype="multipart/form-data" action='register.php' method='post'>
    
    0 讨论(0)
  • 2020-11-30 15:00

    this is a 1 year ago Post but you may still interested .. Check this option in PHP.ini : enable_post_data_reading=off It should be : on otherwise the $_FILES will be empty forever Whether PHP will read the POST data This option is enabled by default. Most likely, you won't want to disable this option globally. It causes $_POST and $_FILES to always be empty.

    0 讨论(0)
  • 2020-11-30 15:01

    first: try to strict programming

    error_reporting(E_ALL | E_STRICT);
    

    also you must use isset for check is index for array available or not

    if (isset($_POST['submitbtn']) && isset($_FILES['avatar'])) {
         // ...
    }
    

    also check php configuraion

    file_uploads    "1"
    upload_max_filesize     "2M"
    post_max_size   "8M"
    max_file_uploads    20
    

    post max size must be larger than upload max file size.

    also as guys said check form enctype

    0 讨论(0)
  • 2020-11-30 15:06

    You should add form attribute enctype="multipart/form-data" to upload files

    0 讨论(0)
提交回复
热议问题