Richard Lloyd
asked on
PHP fwrite to windows absolute path
I have various websites that share directories on windows server, running PHP7.2.
The structure is:
c:\websites\domain1.com\ap p -> Admin website
c:\websites\domain1.com\cl ients\clie ntAdomain. com -> Client A website
c:\websites\domain1.com\cl ients\clie ntBdomain. com -> Client B website
c:\websites\domain1.com\cl ients\clie ntCdomain. com -> Client C website
etc
Each website has subfolders
Any scripts that are shared amongst all the folders throughout all the websites are stored in c:\websites\common and "included" where necessary
I also have a "logs" folder at
c:\websites\logs
I am trying to find a way of using fwrite with an absolute path to always write any logs to the logs folder, from wherever the scripts is called from. Ideally I'd like to use something like
fopen("c:\websites\logs\lo g.txt","+a ");
But I don't think that it works.
Any advice would be appreciated
The structure is:
c:\websites\domain1.com\ap
c:\websites\domain1.com\cl
c:\websites\domain1.com\cl
c:\websites\domain1.com\cl
etc
Each website has subfolders
Any scripts that are shared amongst all the folders throughout all the websites are stored in c:\websites\common and "included" where necessary
I also have a "logs" folder at
c:\websites\logs
I am trying to find a way of using fwrite with an absolute path to always write any logs to the logs folder, from wherever the scripts is called from. Ideally I'd like to use something like
fopen("c:\websites\logs\lo
But I don't think that it works.
Any advice would be appreciated
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In C type languages the '\' is an escape character it means use the '\' in combination with the next character to define another (usually non-printable) character.
So \t (tab) \n (newline / linefeed), \r (carriage return)
When you need to use the '\' as a backslash then escape it with another '\'
Personally I don't like defining constant strings inside the function that uses them - makes maintaining them a pain.
Recommendation:
In your common / config file
Then in your use case
So \t (tab) \n (newline / linefeed), \r (carriage return)
When you need to use the '\' as a backslash then escape it with another '\'
C:\\path
Personally I don't like defining constant strings inside the function that uses them - makes maintaining them a pain.
Recommendation:
In your common / config file
define('LOGPATH', "c:\\websites\\logs\\");
Then in your use case
fopen(LOGPATH . "log.txt","+a");
ASKER
Thanks
The double escaping got me!
The double escaping got me!
Usually each instance logs to its own stracture.
It is isolating each site
Presumably, your php has a database back end you could use access to the db, though it will add to the resource consumption.