dqcwl02022 2019-02-23 10:42
浏览 97
已采纳

注意:未定义的索引:上传文件时的文件

I am trying to do a file check in an MVC framework, and even if I put the file with a jpg format, I am getting error

This is the function that checks the format

public function addAction()
{
     $upload = new Upload();
     if($this->request->isPost())
     {
        $allowed =  array('gif','png' ,'jpg');
        $filename = $_FILES['file']['name'];
        $ext = pathinfo($filename, PATHINFO_EXTENSION);
        if(!in_array($ext,$allowed))
        {
          echo 'error';
        }
        $this->request->csrfCheck();
        $upload->assign($this->request->get());
        $upload->user_id = Users::currentUser()->id;
        if($upload->save())
        {
           Router::redirect('upload');
        }
    }
    $this->view->uploas = $upload ;
    $this->view->displayErrors = $upload->getErrorMessages();
    $this->view->postAction = PROOT . 'upload' . DS . 'add';
    $this->view->render('upload/add');
}

And this is the HTML code:

 <div class="col-lg-6 upload-position center" >
     <input type="file" id="file" name="file" >
 </div>

The isPost method checks if the form method is post

  • 写回答

1条回答 默认 最新

  • doucan2102 2019-02-23 10:54
    关注

    For the next one looking for it :)

    To upload a file you will need enctype="multipart/form-data":

    <form enctype="multipart/form-data">
        <input type="file" name="file"/>
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签)
  • ¥50 sft下载大文阻塞卡死
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失
  • ¥15 springboot+vue 集成keycloak sso到阿里云
  • ¥15 win7系统进入桌面过一秒后突然黑屏
  • ¥30 backtrader对于期货交易的现金和资产计算的问题