上传待导入数据库cakephp的Excel文件时出现问题


problems uploading an Excel file to be imported into the database cakephp

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

非法字符串偏移'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); 
        }
    }
}
?>

and my view

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

我正在尝试实现这个教程:

您很可能需要设置表单的编码类型。

<?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