my code is:
if(isset($_POST['submit']))
{
require_once 'PHPWord.php';
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$section->addText($_POST['editor1']); ///textarea content
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
// Save File
$temp_file_uri = tempnam('', 'xyz');
$objWriter->save($temp_file_uri);
// Download the file:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=myfile.docx');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($temp_file_uri));
flush();
readfile($temp_file_uri);
unlink($temp_file_uri); // deletes the temporary file
}
Comments: __Update:__ I found what the problem was that was only because I don't have office 2007 sorry but the file was open as word file even if I wasn't have office so I thought that will not be the problem maker :( sorry for bothering you but still there is problems before opening the file I receive warning message "said that the content are corrupted and if I'm not ensure from the source I shoudn't open it!" also there is no breaks between lines (as if I wrote all words in one paragraph!
if(isset($_POST['submit']))
{
require_once 'PHPWord.php';
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$section->addText($_POST['editor1']); ///textarea content
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
// Save File
$temp_file_uri = tempnam('', 'xyz');
$objWriter->save($temp_file_uri);
// Download the file:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=myfile.docx');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($temp_file_uri));
flush();
readfile($temp_file_uri);
unlink($temp_file_uri); // deletes the temporary file
}
Comments: __Update:__ I found what the problem was that was only because I don't have office 2007 sorry but the file was open as word file even if I wasn't have office so I thought that will not be the problem maker :( sorry for bothering you but still there is problems before opening the file I receive warning message "said that the content are corrupted and if I'm not ensure from the source I shoudn't open it!" also there is no breaks between lines (as if I wrote all words in one paragraph!