How can I make sure that this path:
new Zend_Log_Writer_Stream(APPLICATION_PATH . '\logs\app.log')
works both on linux and on windows?
A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy.
If you prefer to hard-code the directory separator character, you should use the forward slash ( / ) character. It is the only recognized directory separator character on Unix systems, as the output from the example shows, and is the AltDirectorySeparatorChar on Windows.
A relative path is an address relative to the current directory (i.e., the directory in which a user is currently working). An absolute path (also called a full path) is an address relative to the root directory (i.e., the directory at the very top of the filesystem and which contains all other directories and files).
In Windows you can use either \ or / as a directory separator.
In Linux, the path separator is /
. In Windows, it is either \
or /
. So just use forward slashes and you will be fine.
APPLICATION_PATH . '/logs/app.log'
You can also use DIRECTORY_SEPARATOR
constant instead of \
or /
. Usually you'll want to redefine it to have shorter name, like
define('DS', DIRECTORY_SEPARATOR); $filename = APP . DS . 'logs' . DS . 'file.txt';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With