Difference between revisions of "PHP/file/name"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< PHP‎ | file
Jump to navigation Jump to search
(Created page with "{{fmt/title|PHP filesystem access functionality|folders/directories and file metadata}} ==About== PHP's functionality for managing folders is a mix of classes and standalone f...")
 
Line 13: Line 13:
 
* [https://www.php.net/manual/en/function.basename.php {{fmt/code|basename()}}] returns the last element of a filespec, with some options.
 
* [https://www.php.net/manual/en/function.basename.php {{fmt/code|basename()}}] returns the last element of a filespec, with some options.
 
* [https://www.php.net/manual/en/function.dirname.php {{fmt/code|dirname()}}] returns the filepath to the given file/folder's parent folder.
 
* [https://www.php.net/manual/en/function.dirname.php {{fmt/code|dirname()}}] returns the filepath to the given file/folder's parent folder.
* [https://www.php.net/manual/en/function.pathinfo.php {{fmt/code|pathinfo()}}]] breaks a filespec down into multiple components.
+
* [https://www.php.net/manual/en/function.pathinfo.php {{fmt/code|pathinfo()}}] breaks a filespec down into multiple components.
* [https://www.php.net/manual/en/function.realpath.php {{fmt/code|realpath()}}]] returns a de-contextualized canonical absolute filespec.
+
* [https://www.php.net/manual/en/function.realpath.php {{fmt/code|realpath()}}] returns a de-contextualized canonical absolute filespec.
  
 
==Related==
 
==Related==

Revision as of 21:40, 19 June 2022

PHP filesystem access functionality
folders/directories and file metadata

About

PHP's functionality for managing folders is a mix of classes and standalone functions.

To get a directory listing:

  • «dir()» accepts a filepath to an existing folder and returns a «Directory» object.
  • «glob()» accepts a filespec that includes a file mask, and returns a list of matching filespecs.
    • A file mask in this context can be e.g. «*.php» or «/home/woozle/*.php» but not «~/*.php».
    • The «*» and «?» wildcards are both recognized.
    • The mask may include multiple wildcards, for folders as well as files. Example: «/b*/b*» will return all files beginning with b inside root-level folders beginning with b.

To parse a filespec:

  • «basename()» returns the last element of a filespec, with some options.
  • «dirname()» returns the filepath to the given file/folder's parent folder.
  • «pathinfo()» breaks a filespec down into multiple components.
  • «realpath()» returns a de-contextualized canonical absolute filespec.

Related

  • file: file access functions

Reference