I have downloaded a very small sample file that I am using while trying to get PHPWord to work. I am getting the following error message and can't figure out why.
PHP Fatal error: Class 'PHPWord' not found in /var/www/html/PhpOffice/ex_01.php on line 6
My downloaded small sample program is:
<?php
require_once 'PhpWord.php';
echo realpath (dirname(__FILE__)) . "\n";
$PHPWord = new PHPWord(); <-- <-- <-- LINE 6 HERE
$section = $PHPWord->createSection();
$section->addText('Hello world!');
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=helloWorld.docx");
header("Content-Type: application/docx");
header("Content-Transfer-Encoding: binary");
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('helloWorld.docx');
?>
The internet distributed PhpWord.php file is a bit large for posting but the key point is that lines 43 and 44 and lower contain class code with matching spelling and matching upper/lower case:
class PHPWord
{
For debugging purposes I am running the code from the command line. This seems to give me meaningful error messages.
The "require" seems to be finding the file. The "echo dirname" is posting " /var/www/html/PhpOffice" which is the correct location of both files. In addition, as an experiment I added a typo to the file name in the "require" statement and this caused a "file not found" error. Thus, the "require" looks good.
I have some experience with PHP but this is the first time I have read about classes and namespace in PHP. So far I have no idea what is going wrong. Any suggestions?
Thank you, Bruce