
- PHP Tutorial
- PHP - Home
- PHP - Introduction
- PHP - Environment Setup
- PHP - Syntax Overview
- PHP - Variable Types
- PHP - Constants
- PHP - Operator Types
- PHP - Decision Making
- PHP - Loop Types
- PHP - Arrays
- PHP - Strings
- PHP - Web Concepts
- PHP - GET & POST
- PHP - File Inclusion
- PHP - Files & I/O
- PHP - Functions
- PHP - Cookies
- PHP - Sessions
- PHP - Sending Emails
- PHP - File Uploading
- PHP - Coding Standard
- Advanced PHP
- PHP - Predefined Variables
- PHP - Regular Expression
- PHP - Error Handling
- PHP - Bugs Debugging
- PHP - Date & Time
- PHP & MySQL
- PHP & AJAX
- PHP & XML
- PHP - Object Oriented
- PHP - For C Developers
- PHP - For PERL Developers
- PHP Form Examples
- PHP - Form Introduction
- PHP - Validation Example
- PHP - Complete Form
- PHP login Examples
- PHP - Login Example
- PHP - Facebook Login
- PHP - Paypal Integration
- PHP - MySQL Login
- PHP AJAX Examples
- PHP - AJAX Search
- PHP - AJAX XML Parser
- PHP - AJAX Auto Complete Search
- PHP - AJAX RSS Feed Example
- PHP XML Example
- PHP - XML Introduction
- PHP - Simple XML
- PHP - Simple XML GET
- PHP - SAX Parser Example
- PHP - DOM Parser Example
- PHP Frame Works
- PHP - Frame Works
- PHP - Core PHP vs Frame Works
- PHP Design Patterns
- PHP - Design Patterns
- PHP Function Reference
- PHP - Built-In Functions
- PHP Useful Resources
- PHP - Questions & Answers
- PHP - Useful Resources
- PHP - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 |