$ _FILES错误 - 未定义索引:图像

时间:2012-05-19 06:39:19

标签: php indexing undefined

UploadImage.php

  define ('MAX_FILE_SIZE', 1024 * 50); 

  if ((isset($_POST['MM_insert'])) && ($_POST['MM_insert'] =="uploadImg")) {

    // make sure it's a genuine file upload  
    if (is_uploaded_file($_FILES['image']['tmp_name'])) {
      // replace any spaces in original filename with underscores
      $filename = str_replace(' ', '_', $_FILES['image']['name']);
      // ...
    }
  }

HTML模板:

<form action="UploadImage.php" method="post" 
      enctype="multipart/form-data"  name="uploadImg" id="uploadImg">
  <p>
    <input type="hidden" name="MAX_FILE_SIZE" value="MAX_FILE_SIZE" />
    <label for="image">Upload image:</label>
    <input type="file" name="image" id="image" /> 
  </p>

  <p>
    <input type="submit" name="upload" id="upload" value="Upload" />
  </p>

  <input type="hidden" name="MM_insert" value="uploadImg" />
</form>  

这给出了一个错误; undefined index: image in ....... UploadImage.php 我也给了enctype表单属性...它给出了一个未定义的索引错误:(

1 个答案:

答案 0 :(得分:0)

你可以发布整个php吗?你的php代码中没有session_start()。

编辑:

define ('MAX_FILE_SIZE', 1024 * 50); 必须是KB的值,而不是MB ......

尝试

define ('MAX_FILE_SIZE', 1024000 * 50);