8

I have used Composer to install phpoffice/phpspreadsheet. It was installed in a base 'vendor' directory. However where I am needing to use it is in a subdomain directory. I manually moved it to a different 'vendor' directory.

a bit deeper ../public_html/subdomains/newsite/vendor/

I am calling the code from a file a bit yet deeper ../backend/web/xlsx.php

My actual code is as follows:

<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

require '../../vendor/autoload.php';
$spreadsheet = new Spreadsheet();
?>

With just this simple set I am getting the following fatal error:

Class 'PhpOffice\PhpSpreadsheet\Spreadsheet' not found

I am still learning a bit about namespaces and composer and I may have missed something when I moved the files manually.

Any help would be greatly appreciated.

Thank You!

Scott Johnson
  • 107
  • 1
  • 1
  • 5
  • 1
    Surely moving files around defeats the point of composer, you won't be able to use it to update any dependencies now. There's going to be references to file locations in the composer autoload.php so if you've removed files it won't be able to find them. Either use composer properly, or load your dependencies separately. – Graeme Chapman Jan 06 '18 at 11:05
  • That was my suspicion. Thanks for clarifying that. Will need to figure out how to use composer better. – Scott Johnson Jan 08 '18 at 02:04
  • 1
    Thanks again Graeme. All I had to do was to CD into the subdomain directory and run Composer there and voila, it now works. – Scott Johnson Jan 08 '18 at 13:22

2 Answers2

4

I know it's been a long time since you asked, but it might help others.

In this case when you modify the structure of the vendor the autoload is also updated.

If you are picking up the folder from a local and putting it into production, you should also send the updated autoload.

  • you mean autoload.php file? how to update it? – Jacek Kaczmarek Sep 05 '22 at 09:53
  • He's talking about the __path__ to the autoloader file. It's usually installed relative to the composer.json file but when you move it from that directory you have to update the require directive to it's new location. – jbrahy Sep 27 '22 at 23:46
3

Install this package: composer require phpoffice/phpspreadsheet

Zahid Gani
  • 169
  • 6