Am trying to save a word document using PhpWord 1.0 object Writer within the storage folder in laravel 10 but am getting an exception "mkdir(): No such file or directory". The logic is as follows:
// Set MS Word compatibility to MS Office 2007
$phpWord->getCompatibility()->setOoxmlVersion(12);
$filesBasePath = storage_path('app/references/');
$referenceDir = session()->get('random_files_dir');
if (!empty($referenceDir) and is_dir($filesBasePath . $referenceDir)) {
$absoluteRefPath = $filesBasePath . $referenSceDir;
// Saving the document as OOXML file.
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save($absoluteRefpath . '/references.docx');
} else {
$referenceDir = Str::random(8);
$absoluteRefPath = $filesBasePath . $referenceDir;
if (!File::isDirectory($absoluteRefPath)) {
if (File::makeDirectory($absoluteRefPath, 0755, true, true)) {
// Saving the document as OOXML file.
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save($absoluteRefPath . '/references.docx');
session(['random_files_dir' => $referenceDir]);
}
}
}
return response()->download($absoluteRefPath . '/references.docx')
What might be the issue? Am running on centos 7
I was expecting the word document to be save inside storage/app/references/random folder. The random folder is being created but the the Phpword Object writer throws an exception. the below Line is the one that throws an error;
$objWriter->save(storage_path('references.docx'));
storage/references.docxexist?