2

I am trying to import Joomla CMS to a custom PHP script by this :

define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/' )); 
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
$app = JFactory::getApplication('site');

But this only seems to work when the PHP script is placed in the root directory of the Joomla installation. If I move the script to some other directory, it throws the following error:

Warning: require_once(C:\xampp\htdocs\newfolder/includes/defines.php):
failed to open stream: No such file or directory in C:\xampp\htdocs\newfolder\index.php on line 56

Fatal error: require_once(): Failed opening required
 'C:\xampp\htdocs\newfolder/includes/defines.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\newfolder\index.php on line 56

I am testing on Xampp. In my case, Joomla is installed in the root directory "htdocs" (http://localhost) and the PHP script is placed inside a directory called newfolder (http://localhost/newfolder/index.php).

Help would be appreciated.

1 Answer 1

3

This is because the JPATH_BASE value needs updating as you've moved the file into a new directory.

So replace this:

define('JPATH_BASE', realpath(dirname(__FILE__).'/')); 

with this:

define('JPATH_BASE', realpath(dirname(__FILE__).'/../')); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.