Php File Handling Functions


PHP file handling functions through which we can easily access and manipulate the file. so you can see below the following functions.
Function Descrption
fopen() The fopen() function opens a file or URL. if fopen() fails, it returns false and an error on failure.
fread() The fread() reads from an open file. The function will stop at the end of the file or when it reaches the specified length, whichever comes first. This function returns the read string or false on failure.
fwrite() The fwrite() writes to an open file. The function will stop at the end of the file or when it reaches the specified length, whichever comes first. This function returns the number of bytes written, or false on failure.
fclose() The fclose() function closes an open file. The function returns true on success or false on failure.
file_exists() The file_exists() function check whether or not a file or directory exists. The function returns true if the file or directory exists, otherwise, it returns false.
is_redable() The is_redable() function check whether the specified file is readable. The function returns true if the file is readable.
is_writable() The is_writable() function check whether the specified file is writable. The function returns true if the file is writable.
fgets() The fgets() function returns a line from an open file. The fgets() function stops returning on a new line, at the specified length, or at EOF, whichever comes first. this function returns false on failure.
fgetc() The fgetc() function returns a single character from an open file.
file() The file() function reads a file into a array. Each array element contains a line from the file, with new line still attached.
file_get_contents() The file_get_contents() function reads a file into a string. This function is the prefereed way to read the contents of a file into a string.
file_put_contents() The file_put_contents() function writes string to a file. This function returns the number of character written into file onsuccess, or false on failure.
fseek() The fseek() function seeks in an open file. This function mnew position, forward or backward, specified by the number of bytes.
rewind() The rewind() function "rewinds" the position of the file pointer to the beginning of the file. this function returns true on success, or false on failure.
copy() The copy() function copies a file. this function returns true on success, or false on failure.
unlink() The unlink() function deletes a file. this function returns true on success, or false on failure.
rename() The rename() function renames a file or directory. this function returns true on success, or false on failure.
move_uploaded_file() The move_uploaded_file() function moves an uploaded file to a new location. this function returns true on success, or false on failure.