带有消息的未捕获异常'PHPExcel_Reader_Exception'无法打开以供阅读

时间:2014-07-03 12:24:34

标签: php csv converter phpexcel

我正在为用户创建一个表单,允许他们上传.csv个文件和xls/xlsx个文件。目前,该程序允许他们上传.csv个文件,这些文件用于更新我正在处理的Oracle 11g数据库。但是,我似乎无法弄清楚如何打开,然后将xsl/xlsx文件改为csv。我一直收到这个错误:

Fatal error: Uncaught exception 'PHPExcel_Reader_Exception' with message 'Could not open uploaded.xls for reading! File does not exist, or it is not readable.' in /opt/apache/servers/planninganddesign/htdocs/LG/SLCCA/Classes/PHPExcel/Shared/OLERead.php:80 Stack trace: #0 /opt/apache/servers/planninganddesign/htdocs/LG/SLCCA/Classes/PHPExcel/Reader/Excel5.php(1164): PHPExcel_Shared_OLERead->read('uploaded.xls') #1 <DIRECTORY> (612): PHPExcel_Reader_Excel5->_loadOLE('uploaded.xls') #2 /opt/apache/servers/planninganddesign/htdocs/LG/SLCCA/update_handler2.php(12): PHPExcel_Reader_Excel5->load('uploaded.xls') #3 {main} thrown in /opt/apache/servers/planninganddesign/htdocs/LG/SLCCA/Classes/PHPExcel/Shared/OLERead.php on line 80 

这是一个很长的错误,但我认为第一行是我目前的主要问题。

update2.php (表格)[我怀疑你需要这个]:

<?php require('reader.php'); ?>

<form name="file" enctype="multipart/form-data" action="update_handler2.php" method="post" >

   <u>GF:</u> <input type="file" name="uploaded"><br>
   <u>GF:</u> <input type="number" name="numbers"><br>

   <input type="submit" value="Submit">

</form>

update_handler2.php (处理程序):

<?php require_once'Classes/PHPExcel/IOFactory.php'; ?>

<?php

    $file = $_FILES['uploaded']['tmp_name'];

    $inputFileType = 'Excel5';
    $inputFileName = '$file';

    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcelReader = $objReader->load($inputFileName);

    $loadedSheetNames = $objPHPExcelReader->getSheetNames();

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcelReader, 'CSV');

    foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
        $objWriter->setSheetIndex($sheetIndex);
        $objWriter->save($loadedSheetName.'.csv');
    }

?>

有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:7)

$inputFileName = '$file';

您的文件是否真的被称为$file(您将其引用为字符串文字)....或者是变量$file

中的文件名
$inputFileName = $file;