Home > Backend Development > PHP Tutorial > Detailed explanation of PHP Directory function_PHP tutorial

Detailed explanation of PHP Directory function_PHP tutorial

WBOY
Release: 2016-07-21 15:12:07
Original
981 people have browsed it

Predefined constants:

DIRECTORY_SEPARATOR (string): Directory separator

PATH_SEPARATOR (string): path separator


bool chdir ( string $directory ) — change directory

Copy code The code is as follows:

echo getcwd() . "n";
chdir('public_html');
echo getcwd() . "n";


bool chroot ( string $directory ) — Changing the root directory is only possible if the system supports it and is running the CLI, CGI or embedded SAPI version.

dir::dir (string $directory)—directory class, there are three methods available: read, rewind (redirect the position pointer inside the file to the beginning of a data stream) and close

Copy code The code is as follows:

$d = dir("E:/work/html");
foreach($d as $k=>$v){
echo $k.'->' .$v. '
';
}
while(false ! == ($entry = $d->read())){
echo $entry."
";
}
$d->close();

void closedir ( resource $dir_handle ) — Close the directory handle

Copy code The code is as follows:

$dir = "/etc/php5/";

if (is_dir($dir)) {
if ($dh = opendir($dir)){
$directory = readdir($dh);
closedir($dh);
}
}

string getcwd ( void )— Get the current working directory

resource opendir ( string $path [, resource $context ] ) — Open directory handle

string readdir ( resource $dir_handle ) — Read an entry from a directory handle

Copy code The code is as follows:

if ($handle = opendir('/path/to/files')) {
echo "Directory handle: $handlen";
echo "Files:n";
while (false !== ($file = readdir($handle))) {
echo "$filen ";
}
closedir($handle);
}

void rewinddir ( resource $dir_handle ) — Resets the directory stream specified by dir_handle to the beginning of the directory

array scandir ( string $directory [, int $sorting_order [, resource $context ]] ) — List files and directories in the specified path

Copy code The code is as follows:

$dir = '/tmp';
$files1 = scandir($dir );
$files2 = scandir($dir, 1);
print_r($files1);
print_r($files2);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326745.htmlTechArticlePredefined constants: DIRECTORY_SEPARATOR (string): Directory separator PATH_SEPARATOR (string): Path separator bool chdir (string $directory )—The code to change the directory copy code is as follows...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template