FCPATH in CodeIgniter
August 7, 2025 ยท AI Conversations
### ๐ What is `FCPATH`?
`FCPATH` is a predefined constant in CodeIgniter that gives the **full server path to the `index.php`** file (the front controller of the application).
### โ
Example:
If your project is located at:
/var/www/html/myapp/
and the `index.php` file is here:
/var/www/html/myapp/index.php
Then:
echo FCPATH;
// Output: /var/www/html/myapp/
—
### ๐ ๏ธ Common Use Cases:
1. **When including/creating files in the root**:
require_once FCPATH . 'vendor/autoload.php';
2. **When saving uploaded files**:
$target_path = FCPATH . 'uploads/' . $filename;
—
### ๐ง Where is `FCPATH` defined?
It is defined in `index.php`:
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);
—
Let me know if you're using CodeIgniter 4 โ the concept is similar, but CI4 uses a different structure (like `ROOTPATH`, `APPPATH`, etc.).
codeignter under fossetts_admin
url bo https://boxoffice.fossettscircus.com/
I want FCPATH shoud map to /home/fossetts/public_html/boxoffice not /home/fossetts/public_html/boxoffice/fossetts_admin/
—
### โ Option 1: Manually redefine `FCPATH` at the top of `index.php`
In `fossetts_admin/index.php`, locate this line:
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);
Replace it with:
define('FCPATH', realpath(__DIR__ . '/../') . DIRECTORY_SEPARATOR);
This will set `FCPATH` to:
/home/fossetts/public_html/boxoffice/
๐ก `__DIR__ . '/../'` moves one level up from the `fossetts_admin` directory.
—
### ๐งช To test:
echo FCPATH;
// Output: /home/fossetts/public_html/boxoffice/
—
### โ Option 2: Define your own constant (if you still want to use default FCPATH)
If you need both:
– The default `FCPATH` (for public file access),
– And another constant pointing to the parent directory,
You can do:
define('BOXOFFICE_PATH', realpath(__DIR__ . '/../') . DIRECTORY_SEPARATOR);
Then use `BOXOFFICE_PATH` wherever needed.
—
Let me know if your `index.php` is in a different location or if you're routing URLs differently via `.htaccess`.