【问题标题】:$_FILES error - undefined index: image$_FILES 错误 - 未定义索引:图像
【发布时间】:2012-05-19 06:39:18
【问题描述】:

上传图片.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 表单属性...bt 它给出了一个未定义的索引错误:(

【问题讨论】:

  • 您的文件过大,如 php.ini 文件中指定的那样
  • 尝试调试 $_FILES['image']['tmp_name'] 或使用 isset。
  • 我使用了 isset 并且错误不再显示但没有数据插入到数据库中...
  • isset 如果文件不存在,则简单地停止代码,当然不会插入任何内容!正如@webtecher 所说,很可能它超过了最大文件大小。检查“错误”索引是否等于 0,或检查大小是否低于阈值
  • 虽然我增加了最大文件大小,但它给出了与未定义索引相同的错误:图像,以及如何检查错误索引是否等于 0,实际上我是 php 的新手,谢谢你!

标签: php indexing undefined


【解决方案1】:

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

编辑:

define ('MAX_FILE_SIZE', 1024 * 50); 必须以 KB 为单位,而不是 MB...

试试

define ('MAX_FILE_SIZE', 1024000 * 50);

【讨论】:

    猜你喜欢
    • 2012-06-27
    • 2017-01-06
    • 1970-01-01
    • 2014-02-11
    • 2017-12-01
    • 1970-01-01
    • 2016-05-15
    • 1970-01-01
    相关资源
    最近更新 更多