Hi,
I am using a link to open a custom file which generate a .docx file.
This is working fine on development maschine with windwos xampp.
When I upload the same project on a host with linux os then I am getting the following error:
Avvorlage.php(44): Cannot access offset of type string on string
What should do to solve this?mpol_ch
It seems to be an issue of php 8.0 and php 8.1.
On the same host when I change the php version to 7.4 then it is working without any problem.
Is there any recommendation to work with php 8.X?mpol_ch
If you want to work with PHP 8, then make sure your PHP version that run by Composer is v8.x, too.
This will generate all the related package that needed by your PHPMaker 2022 project compatible with the PHP code run in v8.x.
arbei
June 7, 2022, 1:40pm
4
mpol_ch wrote:
Avvorlage.php(44): Cannot access offset of type string on string
Review and update your code for PHP 8. You may post your code near the error for discussion.
Hi,
below is the code. This is generating a phpword docx.
I have the issue with php 8.0 and php 8.1.
<?php
$FallNr=$_GET['FallNr']; // Rechnung ID
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('./mpol/vorlagen/customvavorlage.docx');
$faelle="SELECT * FROM faelle WHERE Id =".$FallNr;
$stmt = ExecuteQuery($faelle);
$Rech = $stmt->fetch();
$templateProcessor->setValue('FallNr', $Rech['Id']);
$templateProcessor->setValue('GNr', $Rech['GNr']);
$templateProcessor->setValue('AbtNr', $Rech['Code']);
$templateProcessor->setValue('Parteien', $Rech['Parteien']);
$templateProcessor->setValue('Status', $Rech['Status']);
$templateProcessor->setValue('Bearbeiter', $Rech['Bearbeiter']);
$templateProcessor->setValue('Gerichtschreiber', $Rech['GS']);
//$templateProcessor->setValue('V-AA', date('d.m.Y', strtotime($Rech['V-AA_Ausf'])));
//$templateProcessor->setValue('V-GS', date('d.m.Y', strtotime($Rech['V-GS_Gnhm'])));
$vorstatus="SELECT * FROM vorstatus WHERE Fall =".$FallNr;
$stmt = ExecuteQuery($vorstatus);
$Firm = $stmt->fetch();
$templateProcessor->setValue('VStatus', $vorstatus['Status']);
$templateProcessor->setValue('V-AA', date('d.m.Y', strtotime($vorstatus['V-AA_Ausf'])));
$templateProcessor->setValue('V-GS', date('d.m.Y', strtotime($vorstatus['V-GS_Gnhm'])));
// Achtung: Wir müssen die Anzahl der Zeilen für die wiederholende Familienmembers herausfinden.
// Der erste Eintrag der wiederholende Tabelle soll hier wie FName definiert werden..
setlocale(LC_ALL, array('de_CH.UTF-8','de_CH@chf','de_CH','swissgerman'));
//$filename = './mpol/'.$RId.'rechnung.docx';
//$templateProcessor->saveAs($filename);
$filename ='./mpol/'.$FallNr.'.docx';
//$filename ='rechnung.docx';
//$templateProcessor->saveAs("php://output");
// To Download the created File
ob_end_clean();
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
$templateProcessor->saveAs('php://output');
//readfile($filename);
exit;
?>
mpol_ch
arbei
June 8, 2022, 11:51am
6
You better enable Debug and post the detailed error message shown in the error page or from the log file.
mobhar
June 8, 2022, 11:57am
7
Which code that located on line 44?
Hi,
this code is in line 44
$templateProcessor->saveAs(‘php://output’);When change this to
$filename =$FallNr.‘.docx’;
$templateProcessor->saveAs($filename);Then it is not forcing to download and it is saving on server.
I want the file should be downloaded by user.
Any hints?
mpol_ch