[英]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);
}
}
}
?>
和我的看法
<?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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.