PHP File Handling

PHP File System allows us to create file, read file line by line, read file character by character, write file, append file, delete file and close file.

PHP Open File - fopen()

The PHP fopen() function is used to open a file.

Syntax

snippet
resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )

Example

snippet
Click me for more details...

PHP Close File - fclose()

The PHP fclose() function is used to close an open file pointer.

Syntax

snippet
ool fclose ( resource $handle )

Example

snippet

PHP Read File - fread()

The PHP fread() function is used to read the content of the file. It accepts two arguments: resource and file size.

Syntax

snippet
string fread ( resource $handle , int $length )

Example

snippet

Output

Output
hello php file
Click me for more details...

PHP Write File - fwrite()

The PHP fwrite() function is used to write content of the string into file.

Syntax

snippet
int fwrite ( resource $handle , string $string [, int $length ] )

Example

snippet

Output

Output
File written successfully
Click me for more details...

PHP Delete File - unlink()

The PHP unlink() function is used to delete file.

Syntax

snippet
bool unlink ( string $filename [, resource $context ] )

Example

snippet
Click me for more details...
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents