-2

1.8.0"

the goal of my web application is to have a button that the user clicks on.

The code behind will start to scan all the folders that are in the main rdv folder.

in the rdv folder it contains three folders named 1000, 1001, 1002 these contain .xlsx files.

retrieves the last file .xlsx saved in each of the folders

but after that it doesn't work.

Fatal error: Uncaught PHPExcel_Reader_Exception: Could not open 2.xlsx for reading!

so how i can fix the fatal error and how is possible to read the file to continue the code, i want to get 3 values in the .xlsx file and insert into my database.

thank you for your time.

include 'database.php';
require 'PHPExcel/Classes/PHPExcel.php';
require_once 'PHPExcel/Classes/PHPExcel/IOFactory.php';
 
// receives the 'someAction' value from the index page button.
if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['someAction']))
{
    func();
}

function func()
{
    //calcul the nomber of folder in folder rdv
    $howManyFolder = count(glob('rdv/*', GLOB_ONLYDIR));
    
    //retrieves the last file saved in each of the folders and insert into database
    for ($i = 0; $i < $howManyFolder; $i++) {
        
        $files = scandir("rdv/100$i", SCANDIR_SORT_DESCENDING);
        echo "Recover all files in the folder 100" . $i . "<br>";
        print_r($files ); echo "<br>";
        echo "get the last file inserted in the folder at index 0 <br>";
        $newest_file = $files[0]; print_r($newest_file); echo "<br>";
        
        //load the file .xlsx (but the code bug here -_-)
        $objExcel=PHPExcel_IOFactory::load($newest_file);

        //get all value insinde the .xlsx file
        $dossier = $objExcel->getActiveSheet()->getCell('A3')->getValue();
        $facture = $objExcel->getActiveSheet()->getCell('B21')->getValue();
        $date = $objExcel->getActiveSheet()->getCell('Q1')->getValue();

        //call function to insert these values inside dataBase.
        insertInto($dossier, $facture, $date );
    }
}       
CT14.IT
  • 1,635
  • 1
  • 15
  • 31
MI7QC
  • 1
  • 1
  • Is there any more to the error message after that? I was expecting it to give some further explanation of why it can't open it, such as "File does not exist" or something like that. – ADyson Aug 19 '21 at 23:12
  • please edit your post and remove unused details and text to simplify your question and pay attention to focus on your main problem and explain more about it to help others answer your question. also explain more about your problem/expectation from the above code snippet to help your question be understandable. Goodluck – nima Aug 20 '21 at 10:42
  • you can take a moment and read this article https://stackoverflow.com/help/how-to-ask about how to asking questions also read this article https://stackoverflow.com/help/minimal-reproducible-example about how to ask a good question with minimum requirement. – nima Aug 20 '21 at 10:43

1 Answers1

0

XML Parser: https://www.php.net/manual/en/book.xml.php

Parsing an XML document: https://www.php.net/manual/en/function.xml-parse.php

<?PHP
$stream = fopen('large.xml', 'r');
$parser = xml_parser_create();
// set up the handlers here
while (($data = fread($stream, 16384))) {
    xml_parse($parser, $data); // parse the current chunk
}
xml_parse($parser, '', true); // finalize parsing
xml_parser_free($parser);
fclose($stream);