Search code examples
composer-phpdependency-managementphpspreadsheetphpoffice

PhpOffice/PhpSpreadsheet "Class PhpOffice\PhpSpreadsheet\IOFactory could not be loaded"


I'm at my wit's end.

I installed PhpOffice using composer on my local dev machine and it works fine.

I uploaded my app code to a remote test server, then installed PhpOffice using composer on that server.

On both my local machine and the remote server the directory structure is the same:

project/public/ (contains index.php, etc., etc.)
project/public/vendor (contains psr, phpoffice, autoload.php, etc.)

The relevant code (which is identical on local and remote) is:

<?php 
namespace App\Models;

require 'vendor/autoload.php';      

use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;

But when I attempt to use IOFactory, I get:

Class PhpOffice\PhpSpreadsheet\IOFactory could not be loaded

Only occurs on remote server. I am sure the problem is something dumb but I just cannot figure out what I've done wrong. Everything appears to be identical between local and remote.

Please help.


Solution

  • Well, it was something dumb. My remote server was using PHP version 5.6, while my local server is using PHP version 7.2. Changed the PHP version on remote to 7.2, and that did the trick.