Issue
We are now working in a local environment, rather than working live, which is a good thing. However, I've run into a hiccup I don't know how to fix. My code (CodeIgniter) looks like this:
if (!is_dir(base_url() . 'channel-partners/html/camera-registration/' . $name_url)) {
mkdir(base_url() . 'channel-partners/html/camera-registration/' . $name_url);
}
$handle = fopen('/path/to/file/channel-partners/html/camera-registration/' . $name_url . '/index.html', 'w') or die('Can\'t open file');
fwrite($handle, $html);
fclose($handle);
But since I'm running MAMP, $_SERVER['DOCUMENT_ROOT']
equals Applications/MAMP/htdocs, so that won't work. So what can I do to write a file in PHP that would work in both a production environment and a local environment?
Solution
Use the FCPATH
or APPPATH
constants.
FCPATH
will give you the path to the directory where the front controller is located (index.php).
APPPATH
will give you the path to the application directory.
Usage:
fopen(FCPATH . 'path/relative/to/frontcontroller/etc/' . $name_url . '/index.html', 'w') ...
Answered By - Brendan
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.