Reputation: 9915
I am trying to upload XML file to Phalcon application. I was looking for in documentation and it does not help me I simply can not get any reaction from upload action below. Like it is not happening.
Here is code from controller:
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/');
}
}
Here is code form view (as volt template)
{{ 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 »', 'class': 'btn btn-primary btn-large btn-success') }}
</span>
</form>
I am trying to break the ice with simple 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>
What could be happening? Is there some example of working file upload in phalcon?
Upvotes: 1
Views: 2067
Reputation: 2699
You must set enctype="multipart/form-data" in the form:
{{ form('xml/upload', 'class': 'form-inline', 'method': 'post', 'enctype': 'multipart/form-data') }}
Upvotes: 3