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

        <small id='RY1lS'></small><noframes id='RY1lS'>

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

        PHP 未定义索引错误 $_FILES?

        时间:2023-09-21

        • <legend id='QJl4C'><style id='QJl4C'><dir id='QJl4C'><q id='QJl4C'></q></dir></style></legend>

          <small id='QJl4C'></small><noframes id='QJl4C'>

          <tfoot id='QJl4C'></tfoot>

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

                <tbody id='QJl4C'></tbody>

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

                  问题描述

                  我是 PHP 新手,正在学习 YouTube 上的教程.除了文件上传之外,我在这个文件中的所有内容都在工作,任何帮助将不胜感激.这是我得到的错误:

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

                  <块引用>

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

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

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

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

                  对不起,如果这是一个简单的修复...

                   <?php//de-bugging 在脚本按需要工作后删除它>错误报告(E_ALL);ini_set(display_errors", 1);//结束调试//$form = "<form action='register.php' method='post'><table cellpacing='5px'><tr><td></td><td><font color='red'>*</font>是必填字段.</td></tr><tr><td>名字:</td><td><input type='text' name='firstname' class='textbox'><font color='red'>*</font></td></tr><tr><td>姓氏:</td><td><input type='text' name='lastname' class='textbox'><font color='red'>*</font></td></tr><tr><td>用户名:</td><td><input type='text' name='username' class='textbox'><font color='red'>*</font></td></tr><tr><td>电子邮件:</td><td><input type='text' name='email' class='textbox'><font color='red'>*</font></td></tr><tr><td>密码:</td><td><input type='password' name='password' class='textbox'><font color='red'>*</font></td></tr><tr><td>确认密码:</td><td><input type='password' name='repassword' class='textbox'><font color='red'>*</font></td></tr><tr><td>个人资料图片:</td><td><input name='avatar' type='file' ></td></tr><tr><td>个人资料消息:</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></form>";如果 ($_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']);//头像上传$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) {要求(脚本/connect.php");$query = mysql_query("SELECT * FROM users WHERE username='$username'");$numrows = mysql_num_rows($query);如果($numrows == 0){$query = mysql_query("SELECT * FROM users WHERE email ='$email'");$numrows = mysql_num_rows($query);如果($numrows == 0){$pass = (md5(md5($password)));$date = date(F j, Y");如果($姓名){move_uploaded_file($tmpname, "avatars/$username.$ext");$avatar = "$username.$ext";}别的$avatar = "default_avatar.png";$code = substr(md5(rand(111111111111, 999999999999999999)), 2, 25);mysql_query("插入用户值('', '$firstname', '$lastname', '$username', '$email', '$pass', '$avatar', '$bio', '','', '$code', '', '$date')");$webmaster = "xxxx";$subject = "xxxx";$headers = "From:xxx<$webmaster>";$message = "xxx";邮件($email,$subject,$message,$headers);echo "xxx";}别的echo "那封邮件已经被占用了.$形式";}别的echo "那个用户名已经被占用了.$形式";}别的echo "您没有输入有效的电子邮件.$形式";}别的echo "您的密码不匹配.$形式";}别的echo "您没有填写所有必填字段.$形式";}别的echo "$form";?>

                  <?php require("styles/bottom.php") ;?>

                  解决方案

                  第一:尽量严格编程

                  error_reporting(E_ALL | E_STRICT);

                  你还必须使用isset来检查数组是否可用

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

                  还要检查php配置

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

                  帖子最大大小必须大于上传最大文件大小.

                  也正如人们所说的检查表单enctype

                  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:

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

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

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

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

                  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") ; ?>
                  

                  解决方案

                  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

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

                  上一篇:使用 PDO 处理错误的最佳实践 下一篇:PHP 注意:未定义偏移量:1 读取数据时带数组

                  相关文章

                  最新文章

                    • <bdo id='U8PXg'></bdo><ul id='U8PXg'></ul>
                  1. <legend id='U8PXg'><style id='U8PXg'><dir id='U8PXg'><q id='U8PXg'></q></dir></style></legend>
                    <tfoot id='U8PXg'></tfoot>
                  2. <small id='U8PXg'></small><noframes id='U8PXg'>

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