Reputation: 43
I have Joomla Component administrator/components/com_mycomp
And I have import.php
file in this folder.
How I can access import.php from com_mycomp.php.
require_once('./import.php');
Gives error file not found. Because current path is /administrator
, instead of administrator/components/com_mycomp
.
Upvotes: 1
Views: 1862
Reputation: 3789
use JPATH_BASE;
<?php
require_once(JPATH_BASE.'/directory/subdirectory/import.php');
?>
https://docs.joomla.org/How_to_find_your_absolute_path
Upvotes: 1
Reputation: 61
Best way is to use Joomla constants, use
JPATH_ADMINISTRATOR - The path to the administrator folder.
or
JPATH_COMPONENT_ADMINISTRATOR - The path to the administration folder of the current component being executed.
for more refer- https://docs.joomla.org/Constants
Let me know if still face any issue.
Upvotes: 0
Reputation: 4028
The easiest way is to use PHP's __DIR__
constant, that always points to the current file's directory.
<?php
require_once __DIR__ . '/import.php';
Upvotes: 2