0

I have the following code:

require_once "../vendor/autoload.php";
require_once '../vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php';
$target_dir = "coverImages/";
$target_file = $target_dir . basename($_FILES["excelfile"]["name"]);
move_uploaded_file($_FILES["excelfile"]["tmp_name"], $target_file);
if ($_FILES["excelfile"]["error"] > 0)
{
    echo "Error: " . $_FILES["excelfile"]["error"] . "<br>";
}
else
{
    if (file_exists($target_file)) {
        echo "file exists!";
    }else{
        echo "oh it does not";
    }
    $objPHPExcel = PHPExcel_IOFactory::load($target_file);
}

I am getting the file from an input file. I am moving the file to a location on my server. But I cannot load the file once I have it moved. I am verifying the file exists, but phpoffice won't grab my file when I call load on a Factory and gives me a 500 error. Any advice can help me, thanks in advance.

EDIT: Error returned:

Fatal error: Uncaught Error: Class 'ZipArchive' not found in /app/vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php:94 Stack trace: #0 /app/vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php(268): PHPExcel_Reader_Excel2007->canRead('coverImages/Boo...') #1 /app/vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php(191): PHPExcel_IOFactory::createReaderForFile('coverImages/Boo...') #2 /app/public/upload_file.php(26): PHPExcel_IOFactory::load('coverImages/Boo...') #3 {main} thrown in /app/vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php on line 94

Not sure why there is an error, in my dockerfile I am calling:

RUN apt-get update && \
  apt-get install -y \
    freetds-dev \
    libsybdb5 \
    wget \
    zip

So zip should be installed.

3
  • 2
    did you tried to set display_errors? stackoverflow.com/questions/1053424/… Commented Oct 5, 2017 at 21:19
  • 1
    When you get a 500 from the server, you'll generally find something written to the server logs that will identify the cause of the problem Commented Oct 6, 2017 at 8:12
  • added an edit above, googling the zipArchive for answers. Thanks. Commented Oct 6, 2017 at 12:41

2 Answers 2

0

You are missing the zip extension. Either allow it in your php.ini file or install it.

https://secure.php.net/manual/en/book.zip.php

Sign up to request clarification or add additional context in comments.

Comments

0
PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);

This line from this link and an upgrade to 1.8.1 fixed the problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.