【问题标题】:$_FILES not working in php$_FILES 在 php 中不起作用
【发布时间】:2017-10-04 22:34:26
【问题描述】:

我想上传图片,但出现这样的错误

注意:未定义索引:img in /xxx/xxxx/xxxxx/xxxxx/xxxx/add-currency.php on line 12

代码在这里

if(isset($_POST['submit'])) {

    $logo = $_FILES["img"]["name"];
    $logo_tmp = $_FILES["img"]["tmp_name"];
    $file_path = "images/".$logo;
    move_uploaded_file($logo_tmp, $file_path);  

} 

这里是html代码id

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
    <div class="row clearfix">
        <div class="col-sm-6">
            <label>Logo</label><br>
            <input type="file" name="img" />
        </div>                      
    </div>
    <br>            
    <div class="row clearfix">
        <div class="col-sm-12">
            <button name="submit" class="btn m-btn--pill m-btn--air btn-primary" type="submit" style="float:right;">Submit</button>
        </div>                      
    </div>
</form> 

它的工作另一个演示已完成但不在此文件中

【问题讨论】:

  • 好吧,你的代码允许我上传任何我想上传的木马:)
  • 嗯?你对此感到高兴吗?
  • @bub 可能是木马上传平台,你永远不知道 ;) :p
  • @teeyo 你definitley 成就了我的一天.... :) 笑得停不下来

标签: php html


【解决方案1】:

您的代码是正确的,并且在我这边运行良好。无论您得到什么都不是错误,而是一个不影响功能的通知。

Notice: Undefined index: img in /xxx/xxxx/xxxxx/xxxxx/xxxx/add-currency.php on line 12

这可能是因为您在定义之前使用了 img。即使没有错误,您的代码也可以正常工作,这只是一个通知。

【讨论】:

  • 他只是询问了他收到的通知,而不是关于他要上传的内容。这是他的决定,他有代码。
  • 有 $_POST['img'] 是完整的工作,但不是 $_FILES['img']['name'] 工作
  • $_FILES["img"]["name"];在我这边工作。这是我上传的打印图像名称。
  • 你能粘贴完整的代码,以便我了解错误。
猜你喜欢
  • 2018-10-04
  • 2020-03-12
  • 1970-01-01
  • 2013-10-15
  • 2012-12-25
  • 2012-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多