上传文件时,Php未定义索引错误

时间:2014-08-22 06:01:09

标签: php upload

      <form method="post" action="" enctype="multypart/form-data">
        <div class="row" style="margin-left:70px">
        <p>Carousel Number</p>
          <select name="carousel_num">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="2">3</option>
          </select>
        </div>
        <input type="file" name="pic">
        <input type="submit" name="submit" class="btn btn-primary" value="Upload">
      </form>
<?php
if(isset($_POST['submit'])){
  $carousel_num = $_POST["carousel_num"];
  $tmpname = $_FILES["pic"]['tmp_name'];
  $filename = $_FILES["pic"]['name'];
  $file_ext_arr = explode(".",$filename);
  $file_name = $file_ext_arr[0];
  $ext = end($file_ext_arr);
  if($ext == "jpg" || $ext == "png" || $ext == "jpeg" || $ext == "gif"){
    move_uploaded_file("Carousel_$carousel_num","./upload/".$ext);
    echo "<script>history.go(-1);</script>";
  }else{
    echo "<script>alert(\"only 'jpg, png, jpeg, gif' file is permitted.\");history.back(-1);</script>";
  }
}
?>

大家好,这段代码出错了

Notice: Undefined index: pic in /Applications/MAMP/htdocs/astral/special.php on line 49

像这样。我认为,没有拼写错误。我不知道该怎么办才能让它发挥作用。

请帮助我!!

2 个答案:

答案 0 :(得分:2)

应为enctype="multipart/form-data"

<form method="post" action="" enctype="multipart/form-data">

答案 1 :(得分:1)

不是enctype='multypart/form-data'。正确的是enctype='multipart/form-data'

<form method="post" action="" enctype="multipart/form-data">