"File/Folder Operations" PHP folder/File directory action function ____ function

Source: Internet
Author: User
Tags glob

reprint:http://www.php100.com/html/php/hanshu/2013/0905/4370.html
1. PHP Folder action function


String basename (String path [, string suffix]) gives a string containing a full path to a file, which returns the base file name. If the filename ends with suffix, that part will also be removed.

In Windows, the slash (/) and backslash () can be used as a directory separator. In other circumstances it is a slash (/).

Example:

<?php $path = "/testweb/home.php"; Displays the filename with the file name extension echo basename ($path); Displays a filename without a file name extension echo basename ($path, ". php");?> output:
home.php Home



String dirname (String path)

Gives a string containing a full path to a file, which returns the name of the directory after the file name is removed.

In Windows, the slash (/) and backslash () can be used as a directory separator. In other circumstances it is a slash (/).


Array pathinfo (string path [, int options])

PathInfo () returns a federated array containing the information with path. Includes the following array cells: dirname,basename and extension.

You can specify which cells to return through the parameter options. They include: Pathinfo_dirname,pathinfo_basename and Pathinfo_extension. The default is to return all the cells.


Array Scandir (string $directory [, int $sorting _order [, Resource $context]]) scandir, lists the files and directories in the specified path, returns an array containing the DI Files and directories in the rectory. Success returns an array containing the filename, FALSE if it fails. If directory is not a directory, returns a Boolean value of false and generates a e_warning level error.
Example:
<?php $dir = '/tmp '; $files 1 = scandir ($dir); $files 2 = Scandir ($dir, 1); Print_r ($files 1); Print_r ($files 2);?> output:
Array ([0] =>. [1] =>. [2] => bar.php [3] => foo.txt [4] => Somedir) Array ([0] => somedir [1] => foo.txt [2] => bar.php [3] =>.. [4] =>. )


String Realpath (String path)

Realpath () Expands all symbolic connections and processes the '/./' in the input path, '/. /' and superfluous '/' and return normalized absolute pathname. There is no symbolic connection in the returned path, '/./' or '/... /' ingredient.

Returns FALSE when Realpath () fails, such as if the file does not exist. On the BSD system, if only path does not exist, PHP does not return FALSE as other systems do.


BOOL Is_dir (string filename)

Returns TRUE if the filename exists and is a directory. If filename is a relative path, check its relative path according to the current working directory.

Note: The result of this function will be cached. See Clearstatcache () for more information.


Resource Opendir (string path [, resource context])

Opens a directory handle that can be used in subsequent closedir (), Readdir (), and Rewinddir () calls.



String Readdir (Resource Dir_handle) returns the file name of the next file in the directory. The file name is returned in the sort in the file system.



void Closedir (Resource dir_handle) closes the directory stream specified by Dir_handle. The stream must be opened before Opendir ().



void Rewinddir (Resource dir_handle) resets dir_handle specified directory stream to the beginning of the directory.


The array glob (string pattern [, int flags]) Glob () function finds all file paths that match pattern in accordance with the rules used by the libc glob () function, similar to the general SH

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.