1

ms excel file doesn't load in PHPExcel but when i create excelsheets using libreoffice in linux it's load and upload in database.

        $temp=$_FILES['file']['tmp_name'];
        $destination = "/var/www/html/recovery";
        move_uploaded_file($temp,$destination."/"."recovery"."."."xlsx");
        chmod("/var/www/html/recovery/recovery.xlsx", 0777);
        $inputFileName ='recovery.xlsx';

  try 
  {
         $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
         $objReader = PHPExcel_IOFactory::createReader($inputFileType);
         $objPHPExcel =$objReader->load($inputFileName);

   }
   catch(Exception $e) 
   {
    die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
   }

  $allDataInSheet = $objPHPExcel->getActiveSheet()- >toArray(null,true,true,true);
  $arrayCount = count($allDataInSheet);  

what i do for upload all type of excel file in database using PHPExcel.

Maksud Mansuri
  • 631
  • 13
  • 26
  • What error messages are displayed? Is anything written to the PHP or webserver logs? What does the call to `identify()` return? Is your script running in `/var/www/html/recovery` (a call to `getcwd()` should tell you if it is) otherwise you need to provide a full filepath to `identify()` and `load()`, not simply a filename – Mark Baker Oct 07 '15 at 06:58
  • webserver not give any errore message.i was try everything which you mention in comments but still this problem occure. – Maksud Mansuri Oct 07 '15 at 07:00
  • `identify()` return 'Excel2007'... – Maksud Mansuri Oct 07 '15 at 07:04
  • So how do you know that it isn't reading the file, and isn't simply falling over due to lack of memory when you call `toArray()`? – Mark Baker Oct 07 '15 at 07:15
  • bcoz i insert excel data in mysql database so when i upload ms excel file data doesn't insert in database but same excel data insert when i create in linux libreoffice excel file. – Maksud Mansuri Oct 07 '15 at 07:18
  • when excel file create in windows then the file is not uplode in database...that is the main issue....other wise everthing works fine...it's might be extension issue... – Maksud Mansuri Oct 07 '15 at 07:24
  • That doesn't answer the question I asked at all..... if you put a `die('HELLO WORLD');` statement ___after___ the load, do you see that output..... ie is the `load()` failing or is the `toArray()` failing – Mark Baker Oct 07 '15 at 07:36
  • PHPExcel is highly unlikely to fail on a load() without displaying some kind of error, or writing something to the logs..... but running out of memory is the most common failure, especially when telling PHPExcel to build a large array in memory – Mark Baker Oct 07 '15 at 07:37
  • And an issue simply saying "my file doesn't load" and no further information at all is impossible to fix..... I can only fix that issue with more information, so do some basic debugging, or check the logs, or provide the file – Mark Baker Oct 07 '15 at 07:39
  • What makes you think it might be an extension issue? PHPExcel identifies the file as an Excel2007 file, so that doesn't seem to be a problem – Mark Baker Oct 07 '15 at 07:40
  • yes u are right the problem in `toArray()`....what is the solution – Maksud Mansuri Oct 07 '15 at 08:25
  • The solution is to avoid building a large array in memory: perhaps simply to iterate over the rows using PHPExcel's iterators, and process the spreadsheet data a row at a time.... but without knowing what you're trying to do with the data, I can't offer anything beyond that very general suggestion – Mark Baker Oct 07 '15 at 08:26
  • thank you for your response and answer...i will try your given solution... – Maksud Mansuri Oct 07 '15 at 08:31

0 Answers0