I have a controller that can import data from an excel file using PhpSpreadsheet and I installed it with composer.
It works when I use it on my local computer
but after I upload it to the server Debian, the error showed
Class 'PhpOffice\PhpSpreadsheet\Reader\Xls' not found
this is my Controller code
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
public function import()
{
$this->loadModel('Students');
$group_id = $this->request->getData()['group_id'];
$files = $this->request->getUploadedFiles();
$files['import']->getClientFileName();
$tmpFilePath = $files['import']->getStream()->getMetadata('uri');
$files['import']->getStream()->close();
$myname = $this->request->getData()['import']->getClientFileName();
$myext = substr(strchr($myname, "."), 1);
if ($myext == 'xls') {
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
}else if($myext == 'xlsx'){
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
}
$spreadsheet = $reader->load($tmpFilePath);
$sheet = $spreadsheet->getActiveSheet()->toArray();
foreach ($sheet as $key => $excel){
if ($key == 0) {
continue;
}
$data = [
'nis' => $excel[1],
'name' => $excel[2],
'password' => $excel[1],
'group_id' => $group_id,
];
$student = $this->Students->newEmptyEntity();
$student = $this->Students->patchEntity($student, $data);
if ($excel[1] != null AND $excel[2] != null) {
if ($this->Students->save($student)) {
$this->Flash->success(__('The student has been saved.'));
}
}else{
$this->Flash->error(__('The student could not be saved. Please, try again.'));
}
}
return $this->redirect(['action' => 'detail', $group_id]);
}
Please I need your help