<legend id='TmmEp'><style id='TmmEp'><dir id='TmmEp'><q id='TmmEp'></q></dir></style></legend>
    • <bdo id='TmmEp'></bdo><ul id='TmmEp'></ul>
    <tfoot id='TmmEp'></tfoot>

        <i id='TmmEp'><tr id='TmmEp'><dt id='TmmEp'><q id='TmmEp'><span id='TmmEp'><b id='TmmEp'><form id='TmmEp'><ins id='TmmEp'></ins><ul id='TmmEp'></ul><sub id='TmmEp'></sub></form><legend id='TmmEp'></legend><bdo id='TmmEp'><pre id='TmmEp'><center id='TmmEp'></center></pre></bdo></b><th id='TmmEp'></th></span></q></dt></tr></i><div id='TmmEp'><tfoot id='TmmEp'></tfoot><dl id='TmmEp'><fieldset id='TmmEp'></fieldset></dl></div>
      1. <small id='TmmEp'></small><noframes id='TmmEp'>

      2. PHP未定义索引错误$_FILES?

        PHP Undefined index error $_FILES?(PHP未定义索引错误$_FILES?)
        <legend id='3B4aR'><style id='3B4aR'><dir id='3B4aR'><q id='3B4aR'></q></dir></style></legend>
        <i id='3B4aR'><tr id='3B4aR'><dt id='3B4aR'><q id='3B4aR'><span id='3B4aR'><b id='3B4aR'><form id='3B4aR'><ins id='3B4aR'></ins><ul id='3B4aR'></ul><sub id='3B4aR'></sub></form><legend id='3B4aR'></legend><bdo id='3B4aR'><pre id='3B4aR'><center id='3B4aR'></center></pre></bdo></b><th id='3B4aR'></th></span></q></dt></tr></i><div id='3B4aR'><tfoot id='3B4aR'></tfoot><dl id='3B4aR'><fieldset id='3B4aR'></fieldset></dl></div>

        <tfoot id='3B4aR'></tfoot>

        <small id='3B4aR'></small><noframes id='3B4aR'>

          • <bdo id='3B4aR'></bdo><ul id='3B4aR'></ul>
                <tbody id='3B4aR'></tbody>

                1. 本文介绍了PHP未定义索引错误$_FILES?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 PHP 新手,正在关注 YouTube 上的教程.除了文件上传之外,我在这个文件中拥有一切工作,任何帮助将不胜感激.这是我得到的错误:

                  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 error i am getting:

                  *注意:我已经找了很多次了,但找不到与 $_FILES 相关的未定义索引错误...

                  *NOTE: I have looked for this many times, but could not find undefined index error relevant to $_FILES...

                  注意:未定义索引:第 95 行/Applications/xxx 中的头像

                  Notice: Undefined index: avatar in /Applications/xxx on line 95

                  注意:未定义索引:第 96 行/Applications/xxx 中的头像

                  Notice: Undefined index: avatar in /Applications/xxx on line 96

                  注意:未定义索引:第 97 行/Applications/xxx 中的头像

                  Notice: Undefined index: avatar in /Applications/xxx on line 97

                  注意:未定义索引:第 98 行/Applications/xxx 中的头像

                  Notice: Undefined index: avatar in /Applications/xxx on line 98

                  抱歉,如果这是一个简单的修复...

                  Sorry for this if it is a simple fix...

                              <?php $title = "Register";?>
                          <?php require ("styles/top.php") ; ?>           
                          <?php //de-bugging remove this after script works as desired>
                          error_reporting(E_ALL);
                           ini_set("display_errors", 1); 
                          //end de-bugging//
                          
                          $form = "<form action='register.php' method='post'>
                          <table cellspacing='5px'>
                              <tr>
                                  <td></td>
                                  <td><font color='red'>*</font> are required fields.</td>
                              </tr>
                              <tr>
                                  <td>First Name:</td>
                                  <td><input type='text' name='firstname' class='textbox'><font color='red'> *</font></td>
                              </tr>
                              <tr>
                                  <td>Last Name:</td>
                                  <td><input type='text' name='lastname' class='textbox'><font color='red'> *</font></td>
                              </tr>
                              <tr>
                                  <td>Username:</td>
                                  <td><input type='text' name='username' class='textbox'><font color='red'> *</font></td>
                              </tr>
                              <tr>
                                  <td>Email:</td>
                                  <td><input type='text' name='email' class='textbox'><font color='red'> *</font></td>
                              </tr>
                              <tr>
                                  <td>Password:</td>
                                  <td><input type='password' name='password' class='textbox'><font color='red'> *</font></td>
                              </tr>
                              <tr>
                                  <td>Confirm Password:</td>
                                  <td><input type='password' name='repassword' class='textbox'><font color='red'> *</font></td>
                              </tr>
                              <tr>
                                  <td>Profile Picture:</td>
                                  <td><input name='avatar' type='file' ></td>
                              </tr>
                              <tr>
                                  <td>Profile Message:</td>
                                  <td><textarea name='bio' cols='35' rows='5' class='textbox'></textarea></td>
                              </tr>
                              <tr>
                                  <td></td>
                                  <td><input type='submit' name='submitbtn' value='Submit' class='button'></td>
                                  
                              </tr>
                          </table>
                          </form>";
                          
                          
                          if ($_POST['submitbtn']) {
                              
                              $firstname = strip_tags($_POST['firstname']);
                              $lastname = strip_tags($_POST['lastname']);
                              $username = strip_tags($_POST['username']);
                              $email = strip_tags($_POST['email']);
                              $class = ($_POST['class']);
                              $password = strip_tags($_POST['password']);
                              $repassword = strip_tags($_POST['repassword']);
                              $bio = strip_tags($_POST['bio']);
                              //AVATAR UPLOAD
                              $name = $_FILES['avatar'] ['name'];
                              $type = $_FILES['avatar'] ['type'];
                              $size = $_FILES['avatar'] ['size'];
                              $tmpname = $_FILES['avatar'] ['tmpname'];
                              $ext = substr($name, strrpos($name, '.'));
                              
                  
                              
                              if ($firstname && $lastname && $username && $email && $password && $repassword) {
                                  if ($password == $repassword) {
                                      if (strstr($email, "@") && strstr($email, ".") && strlen($email) >= 6) {
                                          
                                          require("scripts/connect.php");
                                          
                                          $query = mysql_query("SELECT * FROM users WHERE username ='$username'");
                                          $numrows = mysql_num_rows($query);
                                          if ($numrows == 0) {
                                          
                                              $query = mysql_query("SELECT * FROM users WHERE email ='$email'");
                                              $numrows = mysql_num_rows($query);
                                              if ($numrows == 0) {
                                              
                                                  $pass = (md5(md5($password)));
                                                  $date = date("F j, Y");
                  
                                                  if($name){
                                                          move_uploaded_file($tmpname, "avatars/$username.$ext");
                                                          $avatar = "$username.$ext";
                                                          }
                                                          else
                                                              $avatar = "default_avatar.png";
                                                          
                                                      $code = substr(md5(rand(111111111111, 99999999999999999)), 2, 25);  
                                              
                                                  
                                                  mysql_query("INSERT INTO users VALUES ('', '$firstname', '$lastname', '$username', '$email', '$pass', '$avatar', '$bio', '', '', '$code', '', '$date')"); 
                                                  
                                                      $webmaster = "xxxx";
                                                      $subject = "xxxx";
                                                      $headers = "From:xxx<$webmaster>";
                                                      $message = "xxx";
                                                      
                                                      mail($email, $subject, $message, $headers);
                                                      
                                                      echo "xxx";
                                                                          
                                              }
                                              else
                                                  echo "That email is already taken. $form";
                                          }
                                          else
                                              echo "That username is already taken. $form";
                                          
                                      }
                                      else
                                          echo "You did not enter a valid email. $form";
                                  
                                  }
                                  else
                                      echo "Your passwords did not match. $form";
                              }
                              else
                                  echo "You did not fill in all of the required fields. $form";
                                  
                              }
                              else
                                  echo "$form";
                              
                              ?>
                          
                              </div>
                              <?php require ("styles/bottom.php") ; ?>
                  

                  推荐答案

                  首先:尽量严格编程

                  error_reporting(E_ALL | E_STRICT);
                  

                  您还必须使用 isset 来检查数组的索引是否可用

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

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

                  还要检查 php 配置

                  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.

                  也正如大家所说的检查表格 enctype

                  also as guys said check form enctype

                  这篇关于PHP未定义索引错误$_FILES?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)
                2. <small id='PQ6D2'></small><noframes id='PQ6D2'>

                    <bdo id='PQ6D2'></bdo><ul id='PQ6D2'></ul>

                        <tbody id='PQ6D2'></tbody>

                      <legend id='PQ6D2'><style id='PQ6D2'><dir id='PQ6D2'><q id='PQ6D2'></q></dir></style></legend><tfoot id='PQ6D2'></tfoot>
                            <i id='PQ6D2'><tr id='PQ6D2'><dt id='PQ6D2'><q id='PQ6D2'><span id='PQ6D2'><b id='PQ6D2'><form id='PQ6D2'><ins id='PQ6D2'></ins><ul id='PQ6D2'></ul><sub id='PQ6D2'></sub></form><legend id='PQ6D2'></legend><bdo id='PQ6D2'><pre id='PQ6D2'><center id='PQ6D2'></center></pre></bdo></b><th id='PQ6D2'></th></span></q></dt></tr></i><div id='PQ6D2'><tfoot id='PQ6D2'></tfoot><dl id='PQ6D2'><fieldset id='PQ6D2'></fieldset></dl></div>