文件输入不提供所有文件信息

时间:2013-02-25 13:54:34

标签: cakephp cakephp-2.0

在我的表格中,我有:

<input type="file" name="data[Speciality][background_image]" id="background_image" class="hide">

这是控制器中“捕获”的请求数据:

public 'data' => 
    array (size=3)
      'modified' => string '0' (length=1)
      'Speciality' => 
        array (size=2)
          'name' => string 'addfsdfsdf' (length=10)
          'background_image' => string 'test.jpg' (length=8)

如您所见,只提供了文件名,它应该是这样的:

[name] => test.jpg
[type] => image/jpeg
[tmp_name] => C:\server\tmp\php5A.tmp
[error] => 0
[size] => 560

有什么问题?

1 个答案:

答案 0 :(得分:2)

您可能忘记阅读有关如何处理文件上传的文档。

确保你的create()方法中有type =&gt;文件:

echo $this->Form->create('Speciality', array('type' => 'file'));

请参阅http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-create