PHP gets the absolute path to the file in code of above the directory
- 2020-05-05 11:04:37
- OfStack
PHP gets the absolute path to the file
chdir
() function Definition and usage of
The chdir() function changes the current directory to the specified directory.
If successful, the function returns true, otherwise false.
Grammar
The chdir(directory) parameter describes
directory required. Specifies the new current directory.
Example
Output:
C:\testweb\main
C:\testweb\main\images
<?php
echo __FILE__ ; // Get the absolute address of the current file, the result: D:\www\test.php
echo dirname(__FILE__); // Get the absolute directory where the current file is located, the result: D:\www\
echo dirname(dirname(__FILE__)); // Get the previous directory name of the current file, the result: D:\
?>
chdir
() function Definition and usage of
The chdir() function changes the current directory to the specified directory.
If successful, the function returns true, otherwise false.
Grammar
The chdir(directory) parameter describes
directory required. Specifies the new current directory.
Example
<?php
// Get the current directory
echo getcwd();
echo "<br />";
// Change for images directory
chdir("images");
echo "<br />";
echo getcwd();
?>
Output:
C:\testweb\main
C:\testweb\main\images