Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi
I create in php a form which user can upload a excel file.
if the file isnt excel then a message ask from the user to upload the correct file
else with php i display the excel as table in html.
My problen is this
"Fatal error: Array and string offset access syntax with curly braces is no longer supported in C:\Users\meeting room\Downloads\PHPExcel-1.8\PHPExcel-1.8\Classes\PHPExcel\Shared\String.php on line 526"

What is this and how can i solved.






<body>
      <form action="" method="post" enctype="multipart/form-data">
        <label for="excel-file"><h2>Ανέβασε το αρχείο σου:</h2></label>
        <input type="file" name="excel-file" id="excel-file">
        <input type="submit" value="Upload">
      </form>


<?php
    require_once '/Users/Downloads/PHPExcel-1.8/PHPExcel-1.8/Classes/PHPExcel.php';

    if(isset($_FILES['excel-file'])) {
      $file_name = $_FILES['excel-file']['name'];
      $file_size = $_FILES['excel-file']['size'];
      $file_tmp = $_FILES['excel-file']['tmp_name'];
      $file_type = $_FILES['excel-file']['type'];

      $allowed_extensions = array('xls', 'xlsx');
      $file_ext = pathinfo($file_name, PATHINFO_EXTENSION);

      if(in_array($file_ext, $allowed_extensions) === false){
        echo '<div class="text1">Error: Μόνο excel αρχεία επιτρέπονται</div>';
      } else {
        move_uploaded_file($file_tmp, "/Users/Desktop/upload/".$file_name);
        if (file_exists("/Users/Desktop/upload/".$file_name)) {
          echo '<div class="text2">Το αρχείο ανέβηκε με επιτυχία</div>';


                $objReader = PHPExcel_IOFactory::createReaderForFile("/Users/Desktop/upload/".$file_name);
                $objPHPExcel = $objReader->load("/Users/Desktop/upload/".$file_name);

                    $worksheet = $objPHPExcel->getActiveSheet();

                    $highest_row = $worksheet->getHighestRow();
                    $highest_column = $worksheet->getHighestColumn();

                    echo '<table border="1">';
                    for ($row = 1; $row <= $highest_row; $row++) {
                    echo '<tr>';
                    for ($col = 'A'; $col <= $highest_column; $col++) {
                        $cell_value = $worksheet->getCell($col.$row)->getValue();
                        echo '<td>'.$cell_value.'</td>';
                    }
                    echo '</tr>';
                }
                echo '</table>';
        }
      }
    }
?>
</body>


What I have tried:

i seached on google
i dont find something to help me
Posted
Updated 22-Feb-23 22:25pm

You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

And since we have no idea what line is number 526 and no way to access your code to start working it out there is nothing we can do to help you fix it!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you either work it out for yourself, or at least know what you have to tell us in order to get help.
 
Share this answer
 
The error is coming from a third-party library. If you read the home page of that project, you'll see:
PHPExcel - DEAD

PHPExcel last version, 1.8.1, was released in 2015. The project was officially deprecated in 2017 and permanently archived in 2019.

The project has not be maintained for years and must not be used anymore. All users must migrate to its direct successor PhpSpreadsheet[^], or another alternative.
So do as the project commands, and migrate to PhpSpreadsheet - that library is still actively maintained, and supports PHP 7.4 or later.
 
Share this answer
 
Comments
[no name] 23-Feb-23 4:29am    
i fixed just i changed this {} to this [] but know i have a another problem

"Classes\PHPExcel\Reader\Excel2007.php on line 94"

in line 94 is this $zip = new $zipClass;
Richard Deeming 23-Feb-23 4:32am    
Read my solution again: the library you are using is DEAD.

Stop trying to "fix" it one error at a time, and switch to its successor, which is still alive and supported.
[no name] 23-Feb-23 4:33am    
ok and how to use PhpSpreadsheet to my project??
Richard Deeming 23-Feb-23 4:36am    
The GitHub project, which is linked to in my question, has full instructions.
[no name] 23-Feb-23 4:45am    
i dont understand what to change in my code
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900