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 Spark加载本地pipelinemodel报错
  • ¥20 电脑鼠标键盘不好使了
  • ¥15 求糕手!用matlab求解目标规划模型🙏
  • ¥15 画出的分类图不对,求解答一下
  • ¥20 springboot和springcloud版本问题
  • ¥15 ps2手柄控制树莓派小车
  • ¥30 C#:vsto powerpoint的外接程序
  • ¥15 两个同维数组相比,不同位置、出现重复比无意义,而不同位置、不出现重复比,则有意义。把有意义的两个数组放入新的集合MK中。
  • ¥15 写一个可直接调用的函数,将32位有符号数转成另一个无符号的数
  • ¥15 CMAKE+VS2019+QT5.15.2组合进行二次编译