Header ("Content-type:text/html;charset=utf-8");
Server root directory
$webrootpath = $_server[' document_root ');
Simple Get Server root directory
$easywebrootpath = "$DOCUMENT _root\\demo\\20150418\\ss.txt";
Current folder directory, proving that forward slashes and backslashes are mixed with Windows.
$dirnamepath = DirName (__file__). ' /ss.txt ';
Because Windows can back slash and forward slash, other systems can only use forward slashes, forward slashes compatible with all systems, so replace all backslashes with a forward slash
$newwebrootpath = str_replace ("\ \", "/", $easywebrootpath);
$FP =fopen ($newwebrootpath, ' a ');
Fwrite ($fp, "Hello");
Fclose ($FP);
Echo ' <div> $webbrootpath </div> ';
echo "<div>$ $webrootpath </div>";
echo $webrootpath. " </br> ";
echo $easywebrootpath. ' </br> ';
echo $dirnamepath. ' </br> ';
echo "forward slash:". $newwebrootpath;
How PHP project path settings are compatible with all operating systems