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>
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题