Uncaught exception 'PHPExcel_Reader_Exception' with message could not open for reading

22,815
$inputFileName = '$file';

Is your file really called $file (you're quoting it as a string literal).... or is the filename in the variable $file

$inputFileName = $file;
Share:
22,815
Ryan_W4588
Author by

Ryan_W4588

Our name will probably be forgotten. But the differences we make in this world, now that is our legacy. What will yours be?

Updated on May 09, 2020

Comments

  • Ryan_W4588
    Ryan_W4588 almost 4 years

    I am creating a form for users that will allow them to upload .csv files and xls/xlsx files. Currently, the program does allow them to upload .csv files, which are used to update the Oracle 11g database I am working off of. However, I cannot seem to figure out how to open, then right the xsl/xlsx files to csv's. I keep getting this error:

    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 
    

    It's a very long error, but I think just the first line is my main issue at the moment.

    update2.php (form) [I doubt you need this]:

    <?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 (handler):

    <?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');
        }
    
    ?>
    

    Does anyone know how to fix to this issue?

  • Ryan_W4588
    Ryan_W4588 almost 10 years
    Wow, I didn't know putting it in '' makes it a literal. Obvi I'm only a week into programming xD lol! Thanks a lot, this seems to have fixed my error. I will accept answer in 10mins once I can! I appreciate you helping the noob out.
  • Mark Baker
    Mark Baker almost 10 years
    If you use double quotes ("), then PHP will interpolate variable values when it encounters variable names, if you use single quotes ('), then it will be a straight string literal docs
  • Ryan_W4588
    Ryan_W4588 almost 10 years
    You learn something new every day :) I'd up but I need 15 rep for that lol. Thanks a lot!