Hi im using XAMP开发者_如何转开发P to host a site locally.
The DocumentRoot is as follows: DocumentRoot "D:/xampp/htdocs"
The siteDir is in the htdocs folder and has a php folder underneath is.
I am trying to use php fopen
with a file relative to the site root (D:/xampp/htdocs/site)
as follows: $log = fopen("/log.log", "a")
however this is creating the file log.log in D:/log.log
Any ideas why this is creating in D:/ ( I would have expected / to be web root relative)
Many Thanks
The /
indicates you're starting from filesystem root. If you want to do things relative to document root you can do (it's just another method to do this)
chdir($_SERVER['DOCUMENT_ROOT']);
$fp = fopen('log.log', 'w');
With this solution the "working directory" will remain the document root.
you have used an absolute path in your code, so PHP acts right.
write a simple code and take a look at $_SERVER variable:
<?php
echo '<xmp>';
print_r($_SERVER);
echo '</xmp>';
?>
you'll find appropriate key to use in your code. before the log.log
in my case that would be like this:
<?php
$sRoot = $_SERVER['DOCUMENT_ROOT'];
$fp = fopen($sRoot . '/log.log', 'w');
?>
精彩评论