1

I'm using Laravel for my school project and recently found the PHPOffice library. I found some examples in the documentation but I still can't understand how to cope it with Laravel. Installed it with composer and now I want to read some *.docx file. Does someone know how to achieve that? I used this

class ShareController extends Controller {
public function share($hashed_name){

    $ds = DIRECTORY_SEPARATOR;
    $userid = Auth::id();
    $name = basename(__FILE__, '.php');
    $source = storage_path('uploads\\'.$userid.'\\'.$onlyFilename.'_0.docx');
    echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
    $phpWord = IOFactory::load($source);
    // Save file
    echo write($phpWord, basename(__FILE__, '.php'), $writers);
    if (!CLI) {
        include_once 'Sample_Footer.php';
    }

}

But I get

Whoops, looks like something went wrong.
1/1 ErrorException in ShareController.php line 34: Use of undefined constant EOL - assumed 'EOL' 
Alex
  • 485
  • 6
  • 18
  • If you want a newline, use `
    ` (if it's HTML) or "\n" (if it's plain text). `EOL` is not a built-in constant in PHP.
    – Matt Browne Feb 25 '16 at 19:52
  • @MattBrowne Yeah I removed the EOL but get an error again saying: `FatalErrorException in ShareController.php line 38: Call to undefined function App\Http\Controllers\write()` – Alex Feb 25 '16 at 19:55
  • No, but PHP_EOL is a built-in constant – Mark Baker Feb 25 '16 at 19:56
  • But you need to write() using an instance of the relevant PHPWord Writer – Mark Baker Feb 25 '16 at 19:56
  • @MarkBaker How will this happen? – Alex Feb 25 '16 at 19:59
  • It sounds like you need to learn how to write object-oriented PHP. `write()` means you're calling a global function called `write()`, which doesn't exist which is why you're getting that error. I'm not familiar with the specifics of the PHPOffice library, but here's a page with an example that may be better than the one you tried to follow: http://phpword.readthedocs.org/en/latest/general.html. – Matt Browne Feb 25 '16 at 22:08

0 Answers0