This example describes how PHP obtains the current directory location. Share to everyone for your reference. The specific analysis is as follows:
If you want to get the directory of the script file, use the function getcwd () to implement it. The function declaration is as follows:
String getcwd (void);
The current directory string is returned after successful execution, and the failure returns false.
Examples are as follows:
The following will use the GETCWD () function to get the directory for the script file. The code is as follows:
The code is as follows:
$shili = GETCWD (); Get the current script directory
$i = 0;
if (Is_dir ($shili)) {//detect is a legitimate directory
if ($shi = Opendir ($shili)) {//Open Directory
while ($li = Readdir ($shi)) {//Read directory
$i + +;
echo "$i: $li"; }}}//content in the output directory
?>
The result of the operation is as shown.
I hope this article is helpful to everyone's PHP programming.