PHP - Filesystem Functions


Advertisements


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

php_function_reference.htm

Advertisements