doujing4555 2012-05-14 16:04
浏览 26
已采纳

Zend Framework - 验证上传内容(二次验证)

I'm currently having users upload a MS Word Document where I am checking a version within the XML. The controller currently checks isValid() and then hits a library that does the parsing and extraction (since word is an archive). Now since it's technically "valid" already, I need to check the validity again through the library. What is the best course of action in Zend Framework for this?

Cheers from Kohana Land ;)

  • 写回答

1条回答 默认 最新

  • duanbi2003 2012-05-15 06:54
    关注

    I think I understand what you are looking for.
    You are currently calling is valid against the form, your file passes the form validation (correct size, extension ...) now you need to unpack the file and validate the contents.

    I'm going to assume you already have the code to validate the contents and just want to understand how that might be used in the controller.
    '

    public function anyAction() {
    
    $form = new Form();
    //test for $_POST
    if ($this->getRequest()->isPost(){
        //Test form for validity
        if ($form->isValid($this->getRequest()->getPost()){
            //will receive file upload (unless disabled in element) and filter form values,
            //based on filters attached to the elements.
            $data = $form->getValues();
            //placeholder for whatever code is required to validate contents of file
            $validateFile = new MyFileValidator();
            //test for valid file contents
            if ($validateFile->isValid($data['file']){
                //Do some Stuff 
            }
            //if file contents is not valid, display form and populate values with unfiltered values
            $form->populate($this->getRequest()->getPost());
        }
       //if form is not valid, it should stay populated and display element errors
      }
    //if not post send form to view
    $this->view->form = $form;
    }
    

    This example should provide the basic controller workflow for this type of problem. I hope it addresses your question.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程