dongxiao3694
2015-01-13 19:07
浏览 18
已采纳

未定义索引:第12,15,16,17,18,19,20行中的文件

I get errors in this part to upload a file image into a folder an after that save in database, help me please

  11   $allowedExts = array("gif", "jpeg", "jpg", "png");
  12   $temp = explode(".", $_FILES["file"]["name"]);
  13   $extension = end($temp);
  14
  15   if ((($_FILES["file"]["type"] == "image/gif")
  16   || ($_FILES["file"]["type"] == "image/jpeg")
  17   || ($_FILES["file"]["type"] == "image/jpg")
  18   || ($_FILES["file"]["type"] == "image/pjpeg")
  19   || ($_FILES["file"]["type"] == "image/x-png")
  20   || ($_FILES["file"]["type"] == "image/png"))
       && ($_FILES["file"]["size"] < 100000)
       && in_array($extension, $allowedExts)) {
       if ($_FILES["file"]["error"] > 0) {
       echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
      } else {
      if (file_exists("../img/propieties/" . $_FILES["file"]["name"])) {
        echo $_FILES["file"]["name"] . " already exists. ";
      } else {
        move_uploaded_file($_FILES["file"]["tmp_name"],
        "../img/propieties/" . $_FILES["file"]["name"]);
      }
      }
      } else {
       echo "Invalid file";
      }

I got a element input normal into a form with method POST

<input type="file" name="file" id="file">
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duandui2803 2015-01-13 19:12
    已采纳

    You're probably missing your enctype="multipart/form-data" attribute in your <form> tag. Without it the file will not upload.

    <form enctype="multipart/form-data" action="" method="post">
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题