public function submissionAction()
    {
        $this->makeRosaResponse();

        if ($this->getRequest()->isHead()) {
            $this->getResponse()->setHttpResponseCode(204);
        } elseif ($this->getRequest()->isPost()) {
            //Post
            // We get $_FILES variable holding the formresults as xml and all possible
            // attachments like photo's and video's
            $upload = new \Zend_File_Transfer_Adapter_Http();

            // We should really add some validators here see http://framework.zend.com/manual/en/zend.file.transfer.validators.html
            // Returns all known internal file information
            $files = $upload->getFileInfo();

            foreach ($files as $file => $info) {
                // file uploaded ?
                if (!$upload->isUploaded($file)) {
                    print "Why haven't you uploaded the file ?";
                    continue;
                }

                // validators are ok ?
                if (!$upload->isValid($file)) {
                    print "Sorry but $file is not what we wanted";
                    continue;
                }
            }

            //Dit moet een filter worden (rename filter) http://framework.zend.com/manual/en/zend.file.transfer.filters.html
            $upload->setDestination($this->responseDir);

            //Hier moeten we denk ik eerst de xml_submission_file uitlezen, en daar
            //iets mee doen
            if ($upload->receive('xml_submission_file')) {
                $xmlFile = $upload->getFileInfo('xml_submission_file');
                $answerXmlFile = $xmlFile['xml_submission_file']['tmp_name'];
                $resultId = $this->processReceivedForm($answerXmlFile);
                if ($resultId === false) {
                    //form not accepted!
                    foreach ($xml->children() as $child) {
                        $log->log($child->getName() . ' -> ' . $child, \Zend_Log::ERR);
                    }
                } else {
                    //$log->log(print_r($files, true), \Zend_Log::ERR);
                    //$log->log($deviceId, \Zend_Log::ERR);
                    \MUtil_File::ensureDir($this->responseDir . 'forms/' . (int) $this->openrosaFormID . '/');
                    $upload->setDestination($this->responseDir . 'forms/' . (int) $this->openrosaFormID . '/');
                    foreach ($upload->getFileInfo() as $file => $info) {
                        if ($info['received'] != 1) {
                            //Rename to responseid_filename
                            //@@TODO: move to form subdir, for better separation
                            $upload->addFilter('Rename', $resultId . '_' . $info['name'], $file);
                        }
                    }

                    //Now receive the other files
                    if (!$upload->receive()) {
                        $messages = $upload->getMessages();
                        echo implode("\n", $messages);
                    }
                    $this->getResponse()->setHttpResponseCode(201); //Form received ok
                }
            }
        }
    }
public function submissionAction()
    {
        $this->makeRosaResponse();

        if ($this->getRequest()->isHead()) {
            $this->getResponse()->setHttpResponseCode(204);
        } elseif ($this->getRequest()->isPost()) {
            //Post
            // We get $_FILES variable holding the formresults as xml and all possible
            // attachments like photo's and video's
            $upload = new \Zend_File_Transfer_Adapter_Http();

            // We should really add some validators here see http://framework.zend.com/manual/en/zend.file.transfer.validators.html
            // Returns all known internal file information
            $files = $upload->getFileInfo();

            foreach ($files as $file => $info) {
                // file uploaded ?
                if (!$upload->isUploaded($file)) {
                    print "Why haven't you uploaded the file ?";
                    continue;
                }

                // validators are ok ?
                if (!$upload->isValid($file)) {
                    print "Sorry but $file is not what we wanted";
                    continue;
                }
            }

            //Dit moet een filter worden (rename filter) http://framework.zend.com/manual/en/zend.file.transfer.filters.html
            $upload->setDestination($this->responseDir);

            //Hier moeten we denk ik eerst de xml_submission_file uitlezen, en daar
            //iets mee doen
            if ($upload->receive('xml_submission_file')) {
                $xmlFile = $upload->getFileInfo('xml_submission_file');
                $answerXmlFile = $xmlFile['xml_submission_file']['tmp_name'];
                $resultId = $this->processReceivedForm($answerXmlFile);
                if ($resultId === false) {
                    //form not accepted!
                    foreach ($xml->children() as $child) {
                        $log->log($child->getName() . ' -> ' . $child, \Zend_Log::ERR);
                    }
                } else {
                    //$log->log(print_r($files, true), \Zend_Log::ERR);
                    //$log->log($deviceId, \Zend_Log::ERR);
                    \MUtil_File::ensureDir($this->responseDir . 'forms/' . (int) $this->openrosaFormID . '/');
                    $upload->setDestination($this->responseDir . 'forms/' . (int) $this->openrosaFormID . '/');
                    foreach ($upload->getFileInfo() as $file => $info) {
                        if ($info['received'] != 1) {
                            //Rename to responseid_filename
                            //@@TODO: move to form subdir, for better separation
                            $upload->addFilter('Rename', $resultId . '_' . $info['name'], $file);
                        }
                    }

                    //Now receive the other files
                    if (!$upload->receive()) {
                        $messages = $upload->getMessages();
                        echo implode("\n", $messages);
                    }
                    $this->getResponse()->setHttpResponseCode(201); //Form received ok
                }
            }
        }
    }
public function submissionAction ( ) { $ this -> makeRosaResponse ( ) ; if ( $ this -> getRequest ( ) -> isHead ( ) ) { $ this -> getResponse ( ) -> setHttpResponseCode ( 204 ) ; } elseif ( $ this -> getRequest ( ) -> isPost ( ) ) { //Post // We get $_FILES variable holding the formresults as xml and all possible // attachments like photo's and video's $ upload = new \ Zend_File_Transfer_Adapter_Http ( ) ; // We should really add some validators here see http://framework.zend.com/manual/en/zend.file.transfer.validators.html // Returns all known internal file information $ files = $ upload -> getFileInfo ( ) ; foreach ( $ files as $ file => $ info ) { // file uploaded ? if ( ! $ upload -> isUploaded ( $ file ) ) { print "Why haven't you uploaded the file ?" ; continue ; } // validators are ok ? if ( ! $ upload -> isValid ( $ file ) ) { print "Sorry but $file is not what we wanted" ; continue ; } } //Dit moet een filter worden (rename filter) http://framework.zend.com/manual/en/zend.file.transfer.filters.html $ upload -> setDestination ( $ this -> responseDir ) ; //Hier moeten we denk ik eerst de xml_submission_file uitlezen, en daar //iets mee doen if ( $ upload -> receive ( 'xml_submission_file' ) ) { $ xmlFile = $ upload -> getFileInfo ( 'xml_submission_file' ) ; $ answerXmlFile = $ xmlFile [ 'xml_submission_file' ] [ 'tmp_name' ] ; $ resultId = $ this -> processReceivedForm ( $ answerXmlFile ) ; if ( $ resultId === false ) { //form not accepted! foreach ( $ xml -> children ( ) as $ child ) { $ log -> log ( $ child -> getName ( ) . ' -> ' . $ child , \ Zend_Log :: ERR ) ; } } else { //$log->log(print_r($files, true), \Zend_Log::ERR); //$log->log($deviceId, \Zend_Log::ERR); \ MUtil_File :: ensureDir ( $ this -> responseDir . 'forms/' . ( int ) $ this -> openrosaFormID . '/' ) ; $ upload -> setDestination ( $ this -> responseDir . 'forms/' . ( int ) $ this -> openrosaFormID . '/' ) ; foreach ( $ upload -> getFileInfo ( ) as $ file => $ info ) { if ( $ info [ 'received' ] != 1 ) { //Rename to responseid_filename //@@TODO: move to form subdir, for better separation $ upload -> addFilter ( 'Rename' , $ resultId . '_' . $ info [ 'name' ] , $ file ) ; } } //Now receive the other files if ( ! $ upload -> receive ( ) ) { $ messages = $ upload -> getMessages ( ) ; echo implode ( "\n" , $ messages ) ; } $ this -> getResponse ( ) -> setHttpResponseCode ( 201 ) ; //Form received ok } } } }
Accepts the form

Takes two roundtrips:
- first we get a HEAD request that should be answerd with
responsecode 204
- then we get a post that only submits $_FILES (so actual $_POST will be empty)
this will be an xml file for the actuel response and optionally images and/or video
proper responses are
201 received and stored
202 received ok, not stored
Accepts the form