图像上传的未识别索引(php,mysql)

sxpgvts3  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(249)

我一直在犯这个未定义的错误 Undefined index: image in /Applications/XAMPP/xamppfiles/htdocs/buksuapp/completeprofile.php on line 51 我不明白为什么我有这个错误,虽然,我已经检查了文件夹,如果他们在目录中存在,给了应用程序的权限,放置 enctype="multipart/form-data 在形式上,什么都不起作用。
这是我的密码:
html格式

<form action = "" method = "post" runat="server" enctype='multipart/form-data'>
     <input type = "hidden" name = "size" value = "1000000">
     <input type = "file" name = "image" id = "file" accept="image/*" /><br/>
     <input type = "submit" name = "btn_submit" value = "Finish">
</form>

PHP

//Random Generator
function random_str($type = 'alphanum', $length = 8)
{
  switch($type)
  {
      case 'basic'    : return mt_rand();
          break;
      case 'alpha'    :
      case 'alphanum' :
      case 'num'      :
      case 'nozero'   :
              $seedings             = array();
              $seedings['alpha']    = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
              $seedings['alphanum'] = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
              $seedings['num']      = '0123456789';
              $seedings['nozero']   = '123456789';

              $pool = $seedings[$type];

              $str = '';
              for ($i=0; $i < $length; $i++)
              {
                  $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
              }
              return $str;
          break;
      case 'unique'   :
      case 'md5'      :
                  return md5(uniqid(mt_rand()));
          break;
  }
}

if(isset($_POST['btn_submit'])){
  $random_gen = random_str('alphanum', 10);
  $random_gen2 = random_str('alphanum', 10);

  $file = $_FILES['image'];

  #Get File Properties
  $file_name = $file['name'];
  $file_tmp = $file['tmp_name'];
  $file_size = $file['size'];
  $file_error = $file['error'];

  #Get File Extension
  $file_ext = explode('.', $file_name);
  $file_ext = strtolower((end($file_ext)));

  $file_rand_name = "buksunetIMG_".$random_gen."_".$random_gen2;

  $file_name_new = $file_rand_name.".".$file_ext;
  $file_destination = "./profileimgs/".$file_name_new;

  if(move_uploaded_file($file_tmp, $file_destination)){
    #File has been uploaded successfully
    echo "<br/><br/>Successful!";
  } else {
    echo "<br/><br/>Error!";
  }

}//END OF SUBMIT BUTTON

我在youtube上看了一个类似的教程,我们有相同的代码。然而他们的工作,我仍然得到了这个未定义的错误。我怎样才能解决这个问题?

相关问题