CodeIgniter Forums
Defining FCPATH - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: Defining FCPATH (/showthread.php?tid=63400)



Defining FCPATH - Tpojka - 10-26-2015

Hello, 

I am setting project in way I'd like to have two directories available: `public_html` and `app`. 
Directory public_html would be root of domain so I would keep application, system, vendor and composer.json in app directory 
outside of http approach. So far so good. I am setting $application_folder and $system_path variables to fit new locations of respective 
directories (i.e. '../app/application'). Also I was checking other constants to see if those are affected by this change and to be sure everything is well.
I ended up with FCPATH link. 
Since I am working on Windows / wamp, FCPATH is represented as "C:\wamp\www\ci302stable\public_html/" 
and as you can see with slashes mixing.
But when I check BASEPATH there is used str_replace() function to make same case slashes in link 
("define('BASEPATH', str_replace('\\', '/', $system_path));").
I was wondering why such a function is not used for FCPATH.

Regards,


RE: Defining FCPATH - Avenirer - 10-27-2015

It doesn't actually matter, as this is only on Windows which, in the end, is accepting both type of slashes.


RE: Defining FCPATH - Tpojka - 10-27-2015

(10-27-2015, 06:19 AM)Avenirer Wrote: It doesn't actually matter, as this is only on Windows which, in the end, is accepting both type of slashes.

Thank you for reply and valuable explanation.

I know that on Ubuntu server which I am using for hosting online, those are all forward slashes.
So, it wouldn't be bad practice to rewrite slashes since if there is some need such is explode of path etc.
It is good to stick with consistency.


RE: Defining FCPATH - mwhitney - 10-27-2015

PHP Code:
define('FCPATH'dirname(__FILE__).'/'); 

Since the default value is the result of calling the dirname() function and passing the full path and filename of the current file (index.php), the slashes in FCPATH will be consistent with the current platform. If you change the way FCPATH is set, it is up to you to ensure the slashes are consistent. If you choose to explode FCPATH (or any path) on slashes, it is up to you to normalize the slashes before exploding on them.

As far as I know, Windows is the only platform that uses backslashes in paths, and it only does so in filesystem paths (not URLs).


RE: Defining FCPATH - Tpojka - 10-27-2015

(10-27-2015, 09:13 AM)mwhitney Wrote:
PHP Code:
define('FCPATH'dirname(__FILE__).'/'); 

Since the default value is the result of calling the dirname() function and passing the full path and filename of the current file (index.php), the slashes in FCPATH will be consistent with the current platform. If you change the way FCPATH is set, it is up to you to ensure the slashes are consistent. If you choose to explode FCPATH (or any path) on slashes, it is up to you to normalize the slashes before exploding on them.

As far as I know, Windows is the only platform that uses backslashes in paths, and it only does so in filesystem paths (not URLs).

Right.

I used:
PHP Code:
define('FCPATH'str_replace('\\''/'__DIR__).'/');//or dirname(__FILE__) for PHP < 5.3 

(like for `BASEPATH` is used) to get forward slashes on `FCPATH`. 
Seems windows doesn't have a problem reading file(s) from path with forward slashes, 
but two of you already pointed that.
Smile
Thanks.


RE: Defining FCPATH - InsiteFX - 10-28-2015

The Windows file::// as you can see does use forward slashes. Look in your browser if you open a file html etc;


RE: Defining FCPATH - Tpojka - 10-28-2015

Yes, I noticed that too. When file is opened outside local server (wamp/xampp), but only from OS and browser.
All these are general things one should remember.


RE: Defining FCPATH - mwhitney - 10-28-2015

(10-28-2015, 04:30 AM)InsiteFX Wrote: The Windows file::// as you can see does use forward slashes. Look in your browser if you open a file html etc;

The browser converts the file URI into a path usable by the file system. The file systems supported by Windows don't generally use or understand file URIs on their own. MSDN has a detailed blog post about how this was done for IE7 which includes the names of the Windows API functions that perform the conversion (PathCreateFromUrl and UrlCreateFromPath). Those API functions reside in the Windows Shell API, which is a subsystem of the Windows Desktop Environment.

Generally, the Data Access and Storage subsystems in Windows, and especially the local file system APIs, don't understand file:// URIs, they only accept paths in the form \\host\share\directory or C:\directory (where C can be any valid drive letter).

From the few instances I could find in the source code, it appears that PHP performs its own conversion of Windows paths, rather than utilizing the Windows API. This is probably at least in part because the API functions were added primarily for the use of Microsoft's applications, and were not available (or documented) throughout most of the time in which PHP has included this functionality.