1

我正在尝试将 XML 文件上传到 Phalcon 应用程序。我在文档中寻找它对我没有帮助我根本无法从下面的上传操作中得到任何反应。就像它没有发生一样。

这是来自控制器的代码:

class XmlController extends ControllerBase
{
    public function initialize()
    {
        $this->view->setTemplateAfter('main');
        Phalcon\Tag::setTitle('Xml');
        parent::initialize();
    }

    public function indexAction()
    {
    }

    public function uploadAction(){
        if ($this->request->hasFiles() == true) { 
            print_r("Yes");
            //Print the real file names and their sizes
            foreach ($this->request->getUploadedFiles() as $file){
                echo $file->getName(), " ", $file->getSize(), "\n";
            }
        }else{
            print_r("No");
        } 

        return $this->forward('xml/');
    }
}

这是代码表单视图(作为伏特模板)

 {{ form('xml/upload', 'class': 'form-inline', 'method': 'post') }}
    <span>
        {{ file_field('xml', 'class': 'input-xxlarge', 'style' : 'font-size:15px; height:40px; margin-top: 3px;') }}
        {{ submit_button('Upload XML &raquo;', 'class': 'btn btn-primary btn-large btn-success') }}
    </span>
</form>

我试图用简单的 XML 打破僵局

    <?xml version='1.0'?> 
<document>
 <title>Forty What?</title>
 <from>Joe</from>
 <to>Jane</to>
 <body>
  I know that's the answer -- but what's the question?
 </body>
</document>

会发生什么?是否有一些在 phalcon 中上传工作文件的示例?

4

1 回答 1

3

您必须在表单中设置 enctype="multipart/form-data":

 {{ form('xml/upload', 'class': 'form-inline', 'method': 'post', 'enctype': 'multipart/form-data') }}
于 2013-09-23T00:09:41.887 回答