mozaika
(Ilovebreslev)
November 16, 2017, 11:39am
1
Hi all
while debbuging a 404 not found of an image file i noticed something strange
i ran this php builtin func to get cuurent path on runtime:
[size="4"]$curPath = getcwd ();
i got this value :
$curPath
"C:[color="#0000FF "]\[/color]xampp[color="#0000FF "]\[/color]htdocs[color="#0000FF "]\[/color]yii2[color="#0000FF "]\[/color]YES-basic-rbac-school"[/size]
and Yii::getAlias returnes this value:
[size=“4”]Yii::getAlias(’@webroot ’);
"C:[color="#FF0000 "]/[/color]xampp[color="#FF0000 "]/[/color]htdocs[color="#FF0000 "]/[/color]yii2[color="#FF0000 "]/[/color]YES-basic-rbac-school"[/size]
one is with slashes and one with backslashes
what am i missing here?
Thanks in advance…
softark
(Softark)
November 16, 2017, 12:17pm
2
It is a Windows specific behavior of PHP.
On windows realpath() will change unix style paths to windows style.
<?php
echo realpath('/windows/system32');
echo realpath('C:\Program Files\\');
?>
The above example will output:
C:\WINDOWS\System32
C:\Program Files
http://php.net/manual/en/function.realpath.php
It is not only the case for "realpath" bat also for other functions that handle files and directories.
As a consequence, we can write a path in source code using "/" alone, stop worrying about the OS.
alirz23
(Ali Raza)
November 16, 2017, 1:31pm
3
getcwd() returns literately the result of the getcwd sys_call depending on the OS. I would recommend you use DIR constant to figure out the directory path which returns very similar results to getcwd, let php handle all OS specific stuff internally.
for realpath function as suggested by softark you need to give it a path.