I am using Excel Reader to import a excel file into my database. I am also using postgres and cakephp. The first obstacle I encounter is that I get the following error when sending the excel of my view to my controller. this error be in my controller:
Illegal string offset '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.
Take a look at documentation for FormHelper::create() and FormHelper::file() for more details. 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.
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.