php - Error message showing when converting Excel file to Text file -


i found script converting .doc, .docx , .xls/.xlsx file text format. it's converting .doc , .docx file text format. when i'm trying convert excel file it's showing me following error message.

do know why it's showing me error message , how fix ? thank you.

error message :

warning: missing argument 1 docxconversion::xlsx_to_text(), called in d:\software installed\xampp\htdocs\contact-management\class-free.php on line 105 , defined in d:\software installed\xampp\htdocs\contact-management\class-free.php on line 48  notice: undefined variable: input_file in d:\software installed\xampp\htdocs\contact-management\class-free.php on line 52  warning: ziparchive::open(): empty string source in d:\software installed\xampp\htdocs\contact-management\class-free.php on line 52     

php class (class-free.php) :

<?php class docxconversion{     private $filename;      public function __construct($filepath) {         $this->filename = $filepath;     }      private function read_doc() {         $doc = new doc;         $doc->read($this->filename);         return $doc->parse();     }      private function read_docx(){          $striped_content = '';         $content = '';          $zip = zip_open($this->filename);          if (!$zip || is_numeric($zip)) return false;          while ($zip_entry = zip_read($zip)) {              if (zip_entry_open($zip, $zip_entry) == false) continue;              if (zip_entry_name($zip_entry) != "word/document.xml") continue;              $content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));              zip_entry_close($zip_entry);         }// end while          zip_close($zip);          $content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);         $content = str_replace('</w:r></w:p>', "\r\n", $content);         $striped_content = strip_tags($content);          return $striped_content;     }   /************************excel sheet************************************/  function xlsx_to_text($input_file){     $xml_filename = "xl/sharedstrings.xml"; //content file name     $zip_handle = new ziparchive;     $output_text = "";     if(true === $zip_handle->open($input_file)){         if(($xml_index = $zip_handle->locatename($xml_filename)) !== false){             $xml_datas = $zip_handle->getfromindex($xml_index);             $xml_handle = domdocument::loadxml($xml_datas, libxml_noent | libxml_xinclude | libxml_noerror | libxml_nowarning);             $output_text = strip_tags($xml_handle->savexml());         }else{             $output_text .="";         }         $zip_handle->close();     }else{     $output_text .="";     }     return $output_text; }  /*************************power point files*****************************/ function pptx_to_text($input_file){     $zip_handle = new ziparchive;     $output_text = "";     if(true === $zip_handle->open($input_file)){         $slide_number = 1; //loop through slide files         while(($xml_index = $zip_handle->locatename("ppt/slides/slide".$slide_number.".xml")) !== false){             $xml_datas = $zip_handle->getfromindex($xml_index);             $xml_handle = domdocument::loadxml($xml_datas, libxml_noent | libxml_xinclude | libxml_noerror | libxml_nowarning);             $output_text .= strip_tags($xml_handle->savexml());             $slide_number++;         }         if($slide_number == 1){             $output_text .="";         }         $zip_handle->close();     }else{     $output_text .="";     }     return $output_text; }       public function converttotext() {          if(isset($this->filename) && !file_exists($this->filename)) {            // return "file not exists";         }          $filearray = pathinfo($this->filename);         $file_ext  = $filearray['extension'];         if($file_ext == "doc" || $file_ext == "docx" || $file_ext == "xlsx" || $file_ext == "pptx")         {             if($file_ext == "doc") {                 return $this->read_doc();             } elseif($file_ext == "docx") {                 return $this->read_docx();             } elseif($file_ext == "xlsx") {                 return $this->xlsx_to_text();             }elseif($file_ext == "pptx") {                 return $this->pptx_to_text();             }         } else {             return "invalid file type";         }     }  }  //$docobj = new docxconversion("test102.doc"); //$docobj = new docxconversion("content.doc"); //$docobj = new docxconversion("english.doc"); //$docobj = new docxconversion("content.docx"); //$docobj = new docxconversion("test.xlsx"); //$docobj = new docxconversion("test.pptx"); //echo $doctext= $docobj->converttotext();  ?> 

the problem in converttotext() method, calls different converters no arguments, while need $input_file argument.

this fix has make work:

if($file_ext == "doc" || $file_ext == "docx" || $file_ext == "xlsx" || $file_ext == "pptx") {    if($file_ext == "doc") {       return $this->read_doc($this->filename);    } elseif($file_ext == "docx") {       return $this->read_docx($this->filename);    } elseif($file_ext == "xlsx") {       return $this->xlsx_to_text($this->filename);    }elseif($file_ext == "pptx") {       return $this->pptx_to_text($this->filename);    } else {       return "invalid file type";    } } 

also, change line:

$xml_handle = domdocument::loadxml($xml_datas, libxml_noent | libxml_xinclude | libxml_noerror | libxml_nowarning); 

with code:

$xml_handle = new domdocument(); $xml_handle->loadxml($xml_datas, libxml_noent | libxml_xinclude | libxml_noerror | libxml_nowarning); 

because domdocument::loadxml(..) instance method. it's prototype is:

public mixed loadxml ( string $source [, int $options = 0 ] ) 

see php:domdocument details.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -