views:

40

answers:

1

in windows (using apache as server), my file path directory will be C:\xampp\htdocs\mysvn\PhpDocumentor\phpdoc.php. But what happen with other OS such as linux on APACHE, or IIS on windows, Or other OS i don't know and never use ?

i would like to know to make sure i wrote the bullet proof, file reading via PHP.

Care anyone give an example path according to different OS and Server ?

+2  A: 

I often create a configuration file for each project, and inside that define some paths in a few constants. Use those constants any time you want to include files from then on:

// config.php
define('ROOT', dirname(__FILE__));
define('LIBS', ROOT . '/libs');

// some other file.php
include LIBS . '/mylib.php';

Though Windows typically uses backslashes as path separators, it's smart enough to handle both, so using forward slashes is safe.

nickf
@nickf, sorry i have edit the question. I believe your answer is right (before i edit them). But that's not what i'm asked for. Thanks for quick reply ;D
justjoe
@justjoe: what's your question then? if you want to get the current file's directory just use `dirname(__FILE__)`.
nickf
i'm sorry to bother you more about this. My question is more about path structure in other OS. I know in APACHE in Windows but how about other OS / Server environment ? if you have experience about this, please share. i will be grateful
justjoe
@justjoe - could you ask a question then? What do you actually want to know?? If you build your application properly it shouldn't matter at all what path is used for the www directory.
nickf
about the path, i hope so. i just want to be sure. My application work by reading files in the path. Mostly those files use php extension. When i work on localhost, i can not use www. I need to use path such as c:/xampp/htdocs/thefiles.php. So, i wonder about other os path (or maybe other servers). How different its path with my windows path ?
justjoe
they will look something like `/var/www/thefiles.php` but like I said, use the above method and it shouldn't matter at all.
nickf
thanks now a i'm relieve ;D . thank you to you for answering my silly question
justjoe