- PHP Tutorial
- PHP - Home
- PHP - Introduction
- PHP - Environment Setup
- PHP - History
- PHP - Syntax
- PHP - Hello World
- PHP - Comments
- PHP - Variables
- PHP - Echo/Print
- PHP - var_dump
- PHP - $ and $$ Variables
- PHP - Constants
- PHP - Magic Constants
- PHP - Data Types
- PHP - Type Casting
- PHP - Type Juggling
- PHP - Operators
- PHP - Strings
- PHP - Boolean
- PHP - Integers
- PHP - Files & I/O
- PHP - Heredoc & Nowdoc
- PHP - Compound Types
- PHP - File Include
- PHP - Date & Time
- PHP - Scalar Type Declarations
- PHP - Return Type Declarations
- PHP - Spread Operator
- PHP - Null Coalescing Operator
- PHP - Spaceship Operator
- PHP Control Statements
- PHP - Decision Making
- PHP - If…Else Statement
- PHP - Switch Statement
- PHP - For Loop
- PHP - Foreach Loop
- PHP - While Loop
- PHP - Do…While Loop
- PHP - Break Statement
- PHP - Continue Statement
- PHP Arrays
- PHP - Arrays
- PHP - Indexed Array
- PHP - Associative Array
- PHP - Multidimensional Array
- PHP - Array Functions
- PHP - Constant Arrays
- PHP Functions
- PHP - Functions
- PHP - Function Parameters
- PHP - Call by value
- PHP - Call by Reference
- PHP - Default Arguments
- PHP - Named Arguments
- PHP - Variable Arguments
- PHP - Returning Values
- PHP - Passing Functions
- PHP - Recursive Functions
- PHP - Type Hints
- PHP - Variable Scope
- PHP - Strict Typing
- PHP - Anonymous Functions
- PHP - Arrow Functions
- PHP - Variable Functions
- PHP - Global Variables
- PHP Superglobals
- PHP - Superglobals
- PHP - $GLOBALS
- PHP - $_SERVER
- PHP - $_REQUEST
- PHP - $_POST
- PHP - $_GET
- PHP - $_FILES
- PHP - $_ENV
- PHP - $_COOKIE
- PHP - $_SESSION
- PHP File Handling
- PHP - File Handling
- PHP - Open File
- PHP - Read File
- PHP - Write File
- PHP - File Existence
- PHP - Download File
- PHP - Copy File
- PHP - Append File
- PHP - Delete File
- Object Oriented PHP
- PHP - Object Oriented Programming
- PHP Web Development
- PHP - Web Concepts
- PHP - Form Validation
- PHP - Complete Form
- PHP - File Inclusion
- PHP - GET & POST
- PHP - File Uploading
- PHP - Cookies
- PHP - Sessions
- PHP - Sending Emails
- PHP AJAX
- PHP - AJAX Introduction
- PHP - AJAX Search
- PHP - AJAX XML Parser
- PHP - AJAX Auto Complete Search
- PHP - AJAX RSS Feed Example
- PHP Login Example
- PHP - Login Example
- PHP - Facebook Login
- PHP - Paypal Integration
- PHP - MySQL Login
- PHP Advanced
- PHP - MySQL
- PHP - Coding Standard
- PHP - Regular Expression
- PHP - Error Handling
- PHP - Bugs Debugging
- PHP - For C Developers
- PHP - For PERL Developers
- PHP - Frameworks
- PHP - Core PHP vs Frame Works
- PHP - Design Patterns
- PHP - Closure::call()
- PHP - Filtered unserialize()
- PHP - IntlChar
- PHP - CSPRNG
- PHP - Expectations
- PHP - Use Statement
- PHP - Integer Division
- PHP - Deprecated Features
- PHP - Removed Extensions & SAPIs
- PHP - Built-In Functions
- PHP Useful Resources
- PHP - Questions & Answers
- PHP - Useful Resources
- PHP - Discussion
PHP - Filesystem Functions
The file system functions are used to access and manipulate the file system PHP provides you all the possible functions you may need to manipulate a file.
Installation
The error and logging functions are part of the PHP core. There is no installation needed to use these functions.
Runtime Configuration
The behaviour of these functions is affected by settings in php.ini.
Name | Default | Changeable | Changelog |
---|---|---|---|
allow_url_fopen | "1" | PHP_INI_ALL | PHP_INI_ALL in PHP <= 4.3.4. PHP_INI_SYSTEM in PHP < 6. Available since PHP 4.0.4. |
allow_url_include | "0" | PHP_INI_ALL | PHP_INI_SYSTEM in PHP 5. Available since PHP 5.2.0. |
user_agent | NULL | PHP_INI_ALL | Available since PHP 4.0.3. |
default_socket_timeout | "60" | PHP_INI_ALL | Available since PHP 4.3.0. |
from | "" | PHP_INI_ALL | |
auto_detect_line_endings | "0" | PHP_INI_ALL | Available since PHP 4.3.0. |
PHP Error and Logging Constants
PHP − indicates the earliest version of PHP that supports the constant.
You can use any of the constant while configuring your php.ini file.
Sr.No | Constant & Description | PHP |
---|---|---|
1 |
GLOB_BRACE |
|
2 |
GLOB_ONLYDIR |
|
3 |
GLOB_MARK |
|
4 |
GLOB_NOSORT |
|
5 |
GLOB_NOCHECK |
|
6 |
GLOB_NOESCAPE |
|
7 |
PATHINFO_DIRNAME |
|
8 |
PATHINFO_BASENAME |
|
9 |
PATHINFO_EXTENSION |
|
10 |
PATHINFO_FILENAME |
5.2.0 |
11 |
FILE_USE_INCLUDE_PATH Search for filename in include_path |
5.0.0 |
12 |
FILE_APPEND Append content to existing file. |
|
13 |
FILE_IGNORE_NEW_LINES Strip EOL characters |
5.0.0 |
14 |
FILE_SKIP_EMPTY_LINES Skip empty lines |
5.0.0 |
15 |
FILE_BINARY Binary mode |
6.0.0 |
16 |
FILE_TEXT Text mode |
6.0.0 |
List of Functions
PHP − indicates the earliest version of PHP that supports the function.
Sr.No | Function & Description | PHP |
---|---|---|
1 | basename()
Returns filename component of path |
3 |
2 | chgrp()
Changes file group |
3 |
3 | chmod()
Changes file mode |
3 |
4 | chown()
Changes file owner |
3 |
5 | clearstatcache()
Clears file status cache |
3 |
6 | copy()
Copies file |
3 |
7 | delete()
Deletes file |
|
8 | dirname()
Returns directory name component of path |
3 |
9 | disk_free_space()
Returns available space in directory |
4.0.7 |
10 | disk_total_space()
Returns the total size of a directory |
4.0.7 |
11 | diskfreespace()
Alias of disk_free_space() |
4.0.7 |
12 | fclose()
Closes an open file pointer |
3 |
13 | feof()
Tests for end-of-file on a file pointer |
3 |
14 | fflush()
Flushes the output to a file |
4 |
15 | fgetc()
Gets character from file pointer |
3 |
16 | fgetcsv()
Gets line from file pointer and parse for CSV fields |
3 |
17 | fgets()
Gets line from file pointer |
3 |
18 | fgetss()
Gets line from file pointer and strip HTML tags |
3 |
19 | file_exists()
Checks whether a file or directory exists |
3 |
20 | file_get_contents()
Reads entire file into a string |
4.3.0 |
21 | file_put_contents()
Write a string to a file |
5 |
22 | file()
Reads entire file into an array |
3 |
23 | fileatime()
Gets last access time of file |
3 |
24 | filectime()
Gets inode change time of file |
3 |
25 | filegroup()
Gets file group |
3 |
26 | fileinode()
Gets file inode |
3 |
27 | filemtime()
Gets file modification time |
3 |
28 | fileowner()
Gets file owner |
3 |
29 | fileperms()
Gets file permissions |
3 |
30 | filesize()
Gets file size |
3 |
31 | filetype()
Gets file type |
3 |
32 | flock()
Portable advisory file locking |
3 |
33 | fnmatch()
Match filename against a pattern |
4.0.3 |
34 | fopen()
Opens file or URL |
3 |
35 | fpassthru()
Output all remaining data on a file pointer |
3 |
36 | fputcsv()
Format line as CSV and write to file pointer |
5.1.0 |
37 | fputs()
Alias of fwrite() |
3 |
38 | fread()
Binary-safe file read |
3 |
39 | fscanf()
Parses input from a file according to a format |
4.0.1 |
40 | fseek()
Seeks on a file pointer |
3 |
41 | fstat()
Gets information about a file using an open file pointer |
4 |
42 | ftell()
Tells file pointer read/write position |
3 |
43 | ftruncate()
Truncates a file to a given length |
4 |
44 | fwrite()
Binary-safe file write |
3 |
45 | glob()
Find pathnames matching a pattern |
4.0.3 |
46 | is_dir()
Tells whether the filename is a directory |
3 |
47 | is_executable()
Tells whether the filename is executable |
3 |
48 | is_file()
Tells whether the filename is a regular file |
3 |
49 | is_link()
Tells whether the filename is a symbolic link |
3 |
50 | is_readable()
Tells whether the filename is readable |
3 |
51 | is_uploaded_file()
Tells whether the file was uploaded via HTTP POST |
4.0.3 |
52 | is_writable()
Tells whether the filename is writable |
3 |
53 | is_writeable()
Alias of is_writable() |
3 |
54 | lchgrp()
Changes group ownership of symlink |
5.1.2 |
55 | lchown()
Changes user ownership of symlink |
5.1.2 |
56 | link()
Create a hard link |
3 |
57 | linkinfo()
Gets information about a link |
3 |
58 | lstat()
Gives information about a file or symbolic link |
3 |
59 | mkdir()
Makes directory |
3 |
60 | move_uploaded_file()
Moves an uploaded file to a new location |
4.0.3 |
61 | parse_ini_file()
Parse a configuration file |
4 |
62 | pathinfo()
Returns information about a file path |
4.0.3 |
63 | pclose()
Closes process file pointer |
3 |
64 | popen()
Opens process file pointer |
3 |
65 | readfile()
Outputs a file |
3 |
66 | readlink()
Returns the target of a symbolic link |
3 |
67 | realpath()
Returns canonicalized absolute pathname |
4 |
68 | rename()
Renames a file or directory |
3 |
69 | rewind()
Rewind the position of a file pointer |
3 |
70 | rmdir()
Removes directory |
3 |
71 | set_file_buffer()
Alias of stream_set_write_buffer() |
3 |
72 | stat()
Gives information about a file |
3 |
73 | symlink()
Creates a symbolic link |
3 |
74 | tempnam()
Create file with unique file name |
3 |
75 | tmpfile()
Creates a temporary file |
3 |
76 | touch()
Sets access and modification time of file |
3 |
77 | umask()
Changes the current umask |
3 |
78 | unlink()
Deletes a file |
3 |