上载要导入到数据库cakephp的Excel文件的问题

我正在使用Excel Reader将excel文件导入到我的数据库中。 我也使用postgres和cakephp。 我遇到的第一个障碍是,当我的视图的Excel发送到我的控制器时,我得到以下错误。 这个错误是在我的控制器中:

非法string偏移'tmp_name'

这是我的控制器和视图的代码

<?php App::import('Vendor', 'excel_reader2'); class SoyaproductorcomprasController extends AppController { public $components = array('Session','RequestHandler'); public function logout() { $this->redirect($this->Auth->logout()); } public function excel() { if ($this->request->is('post')) { $data = new Spreadsheet_Excel_Reader(); $data->read($this->request->data['SoyaProductorCompra']['excel']['tmp_name']); $this->set('data', $data); } } } ?> 

和我的看法

 <?php echo $this->Form->create('SoyaProductorCompra');?> <?php echo $this->Form->input('excel',array( 'type' => 'file', 'label'=>'Ingrese excel')); echo $this->Form->end('Submit') ?> 

我试图实现这个教程:

您可能需要设置表单的编码types。

 <?php echo $this->Form->create('SoyaProductorCompra');?> 

应该:

 <?php echo $this->Form->create('SoyaProductorCompra', array('enctype' => 'multipart/form-data);?> 

你也可以使用'type'=>'file'而不是enctype。

查看FormHelper :: create()和FormHelper :: file()的文档以获取更多详细信息。 我实际上喜欢使用type属性而不是enctype,因为它将设置enctype并确保表单同时处于POST状态。

http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html