I want to download word and PDF file using PHP

I am using this code for download word file. but its not workout

require 'vendor/autoload.php';

use PhpOffice\PhpWord\PhpWord;

use PhpOffice\PhpWord\IOFactory;

// Create a new PhpWord instance

$phpWord = new PhpWord();

// Add a section

$section = $phpWord->addSection();

// Iterate through categories and points

 

        // Add prayer points

       $section->addText($row['prayer_points']);

        // Add a horizontal line

          

// Save the document

$filename = 'generated_document.docx';

$objWriter = IOFactory::createWriter($phpWord, 'Word2007');

$objWriter->save($filename);

// Provide the file for download

header('Content-Type: application/octet-stream');

header('Content-Disposition: attachment; filename=' . $filename);

header('Content-Length: ' . filesize($filename));

readfile($filename);

// Delete the temporary file after providing for download

unlink($filename);

exit;
Sponsor our Newsletter | Privacy Policy | Terms of Service