我试图导入2010 xlsx文件到CAKEPHP中的mysql数据库。 PHPExcel插件用于Excel操作。PHPExcel插件不会导入cakephp中的文件
我正面临以下问题。
1期 ::我看到下面的错误时,我的观点是从视图中推出
Notice (8): Undefined index: Program
[APP\Controller\ProgramsController.php, line 83]
第2期 ::在浏览xlsx档案时点击提交按钮时,我看到下面的错误。 无法打开import.xlsx阅读!文件不存在。
Error: An Internal Error Has Occurred. Stack Trace
APP\Vendor\PHPExcel\IOFactory.php line 268 → PHPExcel_Reader_Excel2007->canRead(string)
APP\Vendor\PHPExcel\IOFactory.php line 205 → PHPExcel_IOFactory::createReaderForFile(string)
APP\Controller\ProgramsController.php line 87 → PHPExcel_IOFactory::identify(string)
[internal function] → ProgramsController->importexcel()
CORE\Cake\Controller\Controller.php line 490 → ReflectionMethod->invokeArgs(ProgramsController, array)
CORE\Cake\Routing\Dispatcher.php line 191 → Controller->invokeAction(CakeRequest)
CORE\Cake\Routing\Dispatcher.php line 165 → Dispatcher->_invoke(ProgramsController, CakeRequest)
APP\webroot\index.php line 108 → Dispatcher->dispatch(CakeRequest, CakeResponse)
下面是从控制器
<?php
App::import('Helper', 'Number');
include '../vendor/PHPExcel.php';
include '../vendor/PHPExcel/IOFactory.php';
class ProgramsController extends AppController {
var $name = 'Programs';
var $helpers = array('Html', 'Form', 'Time','PhpExcel','Js' => array('Jquery'));
var $uses = array('Program','Customer');
public $components = array('PhpExcel');
function importexcel()
{
$inputFileName = $this->data['Program']['uploadFile'];
if ($inputFileName!='')
{
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($inputFileName);
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$highestRow = $objWorksheet->getHighestRow();
for ($row = 2; $row <= $highestRow; ++$row)
{
$this->data['Program']['cycle_month']=$objWorksheet->getCellByColumnAndRow(1, $row)->getValue();
$this->data['Program']['cycle_year']=$objWorksheet->getCellByColumnAndRow(2, $row)->getValue();
$this->data['Program']['media_partnum']=$objWorksheet->getCellByColumnAndRow(3, $row)->getValue();
$resultarray[$row-2]=$this->data['Program'];
}
if ($this->Program->saveAll($resultarray)) {
$this->Session->setFlash(__('The Program have been saved', true));
}
}
}
}
?>
我的代码和我的看法代码如下。
<?php
echo $this->Form->create('Program',array('id' =>'importexcel','type'=>'post','action'=>'importexcel','url' => array('controller' => 'programs')));
?>
<table>
<tbody>
<tr>
<td>Choose Your File:</td>
<td><input width=200 type="file" name="data[Program][uploadFile]"></td>
<td>
<div>
<?php echo $this->Form->submit('Import Program', array('div'=>false,'name'=>'importexcel'));
?>
</div>
</td>
</tr>
</tbody>
</table>
任何人都可以请帮助解决这个问题,我在网上搜索教程上传擅长使用PHPExcel的CakePHP的例子mysql数据库,但无法找到任何有意义的东西。
如果您可以解释修复或其他任何方法的步骤,那将非常有帮助。
谢谢。
“无法打开import.xlsx for reading!文件不存在”。权限 – burzum 2015-02-09 10:27:50
我已经给了输入文件的完全权限,但仍然得到相同的错误。我新编程,请你详细说明 – 2015-02-09 12:24:10
你可以按照这个http://stackoverflow.com/a/17190330/2460470,可能是帮助你。 – Supravat 2015-02-09 16:33:13