How to get the current directory location in PHP, php gets the current location
The example in this article describes how PHP obtains the current directory location. Share it with everyone for your reference. The specific analysis is as follows:
If you want to get the directory of the script file, you need to use the function getcwd() to achieve it. The function declaration is as follows:
string getcwd ( void ) ;
Returns the current directory string after successful execution, otherwise returns FALSE.
An example is as follows:
The getcwd() function will be used below to obtain the directory of the script file. The code is as follows:
Copy code The code is as follows:
$shili= getcwd () ; //Get the current script directory
$i = 0;
if ( is_dir ( $shili )){
If ($shi = opendir ($shili)){ //Open directory
while ($li = readdir( $shi )){ //Read directory
$i++ ;
echo " $i: $li" ; } } } // Output the contents of the directory
?>
The running results are shown in the figure below.
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/917677.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/917677.htmlTechArticleHow to get the current directory location in PHP, php gets the current directory location. This article describes how PHP gets the current directory location. method. Share it with everyone for your reference. The specific analysis is as follows...