Search code examples
phplaravelphpword

When i tried to open .rtf files but it is opening as .zip


I am working with Laravel 5.8 and i am using phpword to creat .rtf file. When i download it the it is opening as zip file. I changed the file type rtf to docx but i got the same result. enter image description here


Solution

  • With this bellow code i can manage to download the file as RTF instead of Zip archive.

    Ok now I can manage to solve it with bellow code

    ############## Create RTF file ##############
    $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
    $objWriter->save(public_path('Report_File/InfoSec_DFAR_Report_' . $time . '.rtf'));
                    ############## Create RTF file ##############
        
                    ############## Download RTF file ##############
        
                    header("Cache-Control: public"); // needed for internet explorer
                    header("Content-Type: application/rtf");
                    header("Content-Transfer-Encoding: Binary");
                    header("Content-Length:".filesize(public_path('Report_File/filename' . $time . '.rtf')));
                    header("Content-Disposition: attachment; filename=InfoSec_DFAR_Report_".$time. '.rtf');
                    readfile(public_path('Report_File/filename' . $time . '.rtf'));
                    die(); 
    ############## Download RTF file ##############