CakePHP: posted file data not included in request->data

杀马特。学长 韩版系。学妹 提交于 2019-12-03 17:03:08

File upload data can only be found in CakeRequest::$data in case the input element name is passed in an array named data (which is the default when not defining a specific name manually), ie:

<input type='file' name='data[file]'>

In your case however, the element will look like this:

<input type='file' name='file'>

which will cause the files data to be put in CakeRequest::$params[form].

https://github.com/cakephp/cakephp/blob/2.4.0/lib/Cake/Network/CakeRequest.php#L346

So either change the name in the form accordingly:

$this->Form->input('file', array('type' => 'file', 'name' => 'data[file]'));

Or access the file data via CakeRequest::$params[form]:

debug($this->request->params['form']);

Nunser was right (as always)! The problem resulted from customizing the name of the input. When I remove the 'name'=>'...' from the options array, the file shows up as expected. This seems like a bug, but if someone has a better explanation I'd love to hear it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!