0
votes

I am using Typo3 cms. Under the main folder I have different other folders such as typo3, typo3conf, fileadmin etc...

I have created two php files named myphp.php, and myantoher.php inside the main folder, and I used require() in myphp.php. But when that line is reached during execution, I am receiving the following errors:

Warning: require(doc/PHPMailer/class.PHPMailer.php): failed to open stream: No such file or directory in /var/www/domainname.com/doc/contactform.php on line 3 Fatal error: require(): Failed opening required 'doc/PHPMailer/class.PHPMailer.php'

Why am I receiving an error when I try to require() this file?

3
It may be helpful if you include the error message that you are receiving as well as the code that is generating the error.user700390
Please find the error message. Warning: require(doc/PHPMailer/class.PHPMailer.php): failed to open stream: No such file or directory in /var/www/domainname.com/doc/contactform.php on line 3 Fatal error: require(): Failed opening required 'doc/PHPMailer/class.PHPMailer.php'user3463126
Are you certain of the working directory? Does it behave differently if you use an absolute path instead of a relative path?user700390
Use the TYPO3 API to run custom code. A way is to integrate a userFunc via TypoScript. Here's an example (in german) netbrothers.de/typo3-projekte/typo3-tipps/…Urs

3 Answers

2
votes

It's very easy to add PHP or any other files in TYPO3

You have to script

  includeLibs.cookie = fileadmin/cookie/cookie.php

  page.20 = USER_INT
  page.20 {
      userFunc = user_setcookie
  }

For more information about TYPO3 stuff you may visit my blog

https://jainishsenjaliya.wordpress.com/2015/04/01/how-to-include-custome-php-file-in-typo3/

Regards,

Jainish Senjaliya

0
votes

Here you can include your custom PHP file

Using the CONFIG object.

ex:

config.includeLibrary = fileadmin/templates/myscript.php

Using the PAGE object.

ex:

page.100.file = fileadmin/templates/myscript.php

0
votes

FYI. it's not possible to use includeLibs via TypoScript anymore. Instead, ensure to encapsulate code in PHP functions or PHP classes, and load them via the class loader (by putting them in a simple extension) or via Composer's autoload functionality.

You can still call functions/methods then via PHP all around TYPO3 an call them in Frontend via

page.10 = USER_INT
page.10.userFunc = bennis_function

or if it is a method in a class

page.10.userFunc = Benni\Mack\RandomClassName->my_method

If you want to do it quick and dirty, you can require your file in your AdditionalConfiguration.php file and use it everywhere as well.

Still, best approach is using an extension with PHP classes and PSR-4 autoloading.