Php change directory to root
How do i change the directory in php : I tried this : Show
But this doesnt changes the directory. I am using php-cli I will prefer a cross platform solution(i.e. common for windows , linux , mac)
hakre 187k48 gold badges419 silver badges802 bronze badges asked Jul 18, 2011 at 10:01
5 If you want to change to home directory, you can use:
It's even cross-platform this way. EDIT: If you mean "home directory" as top directory on drive, you can use:
answered Jul 18, 2011 at 10:15
Ondrej SlintákOndrej Slinták 30.7k20 gold badges92 silver badges125 bronze badges
Based on the above:
Do you see errors anywhere?
answered Jul 18, 2011 at 11:25
sdolgysdolgy 6,8573 gold badges40 silver badges60 bronze badges
try this one. By single \ you're escaping single quote answered Jul 18, 2011 at 10:05
genesisgenesis 49.8k20 gold badges94 silver badges123 bronze badges 4 (PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8) chroot — Change the root directory Descriptionchroot(string This function is only available to GNU and BSD systems, and only when using the CLI, CGI or Embed SAPI. Also, this function requires root privileges. Calling this function does not change the values of the Parametersdirectory The path to change the root directory to. Return Values Returns ExamplesExample #1 chroot() example
The above example will output: Notes
(PHP 4, PHP 5, PHP 7, PHP 8) chdir — Change directory Descriptionchdir(string Parametersdirectory The new current directory Return Values Returns Errors/Exceptions Throws an error of level ExamplesExample #1 chdir() example
The above example will output something similar to: /home/vincent /home/vincent/public_html NotesCaution If the PHP interpreter has been built with ZTS (Zend Thread Safety) enabled, any changes to the current directory made through chdir() will be invisible to the operating system. All built-in PHP functions will still respect the change in current directory; but external library functions called
using FFI will not. You can tell whether your copy of PHP was built with ZTS enabled using php -i or the built-in constant See Also
nesk at xakep dot ru ¶ 1 year ago
= 'path/to/libraries'; php dot duke at qik dot nl ¶ 13 years ago
;
herwin at snt dot utwente dot nl ¶ 16 years ago
How do I change directories in PHP?The chdir() function changes the current directory.
How do I get to the root directory?To locate the system root directory:
Press and hold the Windows key, then press the letter 'R'. (On Windows 7, you can also click start->run… to get the same dialog box.) Enter the word “cmd” in the program prompt, as shown, and press OK.
What is __ DIR __ in PHP?The __DIR__ can be used to obtain the current code working directory. It has been introduced in PHP beginning from version 5.3. It is similar to using dirname(__FILE__). Usually, it is used to include other files that is present in an included file.
What is chroot PHP?The chroot() function in PHP is an inbuilt function which is used to change the root directory of the current process to directory. The chroot() function changes the current working directory to “/”.
|