I am trying to access files via relative or absolute URL from within Joomla article

For example, inside the article, the following path works: d3.json("../../example.php", ...

but the following relative path does NOT: d3.json("../../php/example.php", ...

and the following absolute path does NOT: d3.json("/php/example.php", ...

Folder structure:



file: configuration.php

file: example.php

folder: php (which also contains example.php)

In other words, Joomla thinks I am 2 folders down from location of configuration.php

and the only location I can access files from is /html/Joomla/ (no subfolders)

please advise the path I should enter to access other locations such as /html/Joomla/php/example.php or /html/Joomla/php/examples/example.php


First off, what these files being referenced are used for is critical to the answer. For instance, if you're making an AJAX call and expect the destination PHP to have access to core Joomla methods and data simply by referencing the file directly will not work as the joomla framework isn't bootstrap'd unless you go through the MVC.

I can show you how to properly reference the files needed, but without knowing the context of how they are being used does not guaranteed the proper path/url will resolve the issue.

That being said, Joomla has predefined constants for paths and a static helper class for URLS to help you construct links in your code. In addition, I would always reference files using the full path or URL to ensure the directing your code is referencing is correct.

For URLS use:

$url = JRoute::_(JUri::root() . 'path/from/website/root/example.php');

For directory paths use:

$path = JPATH_ROOT . '/path/from/website/root/example.php';

Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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