I am trying to add a PHP file to my CakePHP controller using the require "filename.php" but it's not working. here is the error message:
require(filename.php): failed to open stream: No such file or directory
I am trying to add a PHP file to my CakePHP controller using the require "filename.php" but it's not working. here is the error message:
require(filename.php): failed to open stream: No such file or directory
This means the file filename.php
does not exist in the path from your script.
Do a var_dump(getcwd())
to get path of your current working directory. If your file is not in this path, there is your problem.
You will most likely need to use a more specific path to the filename, such as
require(__DIR__ . DIRECTORY_SEPARATOR . 'pathto' . DIRECTORY_SEPARATOR . 'filename.php');
But probably you should be looking at autoloading your file or use the template functionality in CakePHP. In the absolute majority of cases, if you are including a file directly in a framework with include
or require
, there is reason to stop and rethink your solution. Chances are you are doing something wrong.