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.

tcoulson
  • 524
  • 2
  • 7
  • 31
  • 2
    did you tried to set display_errors? https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – icy Oct 05 '17 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 – Mark Baker Oct 06 '17 at 08:12
  • added an edit above, googling the zipArchive for answers. Thanks. – tcoulson Oct 06 '17 at 12:41

2 Answers2

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

Finwe
  • 4,943
  • 2
  • 26
  • 38
0
PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);

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

tcoulson
  • 524
  • 2
  • 7
  • 31