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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵