[英]problems uploading an Excel file to be imported into the database cakephp
I am using Excel Reader to import a excel file into my database. 我正在使用Excel Reader将excel文件导入到我的数据库中。 I am also using postgres and cakephp.
我也在使用postgres和cakephp。 The first obstacle I encounter is that I get the following error when sending the excel of my view to my controller.
我遇到的第一个障碍是,将视图的excel发送到控制器时出现以下错误。 this error be in my controller:
此错误在我的控制器中:
Illegal string offset 'tmp_name'
非法字符串偏移量'tmp_name'
this is the code of my controller and view 这是我的控制器和视图的代码
<?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')
?>
I'm trying to implement this tutorial: 我正在尝试实施本教程:
More than likely you need to set the encoding type of your form. 您很有可能需要设置表单的编码类型。
<?php echo $this->Form->create('SoyaProductorCompra');?>
Should be: 应该:
<?php echo $this->Form->create('SoyaProductorCompra',
array('enctype' => 'multipart/form-data);?>
You can also use 'type' => 'file' instead of enctype. 您也可以使用'type'=>'file'代替enctype。
Take a look at documentation for FormHelper::create() and FormHelper::file() for more details. 查看FormHelper :: create()和FormHelper :: file()的文档以了解更多详细信息。 I actually like using the type attribute instead of enctype since it will set the enctype and make sure the form is POST at the same time.
我实际上喜欢使用type属性而不是enctype,因为它将设置enctype并确保表单同时为POST。
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.