Welcome back to Built-in Functions.
chmod(), chgrp(), chown()
Like the shell commands of the same name, the chmod(), chgrp(), and chown() functions modify the permissions, grop and owner of a directory or file. Here is the syntax of these functions:
In order to change permissions, groups, or owners, the PHP user must be the owner of the file, or the permissions must already be set to allow such change by that user.
The copy() function works much like the cp shell command: It needs a file name and a destination in order to copy a file.
The syntax of copy() is copy(“source file name”, “destination”);
The PHP user must have permissions to write into the destination directory, or the copy() function will fail.
The fopen() function opens a specified file or URL for reading and/or writing. The syntax of fopen() is
To open a URL, use http:// or ftp:// at the beginning of the file name string. You can open URLs only for reading, not writing.
If the file name begins with anything else, the file is opned from the filesystem, and a file pointer to the opened file is returned. Otherwise, the file is assumed to reside on the local filesystem.
The specified mode determines whether the file is opened for reading, writing, or both. The following lists the valid modes.
r – Read only. The file pointer is at the beginning of the file.
r+ – Reading and writing. The file pointer is at the beginning of the file.
w – Write-only. The file pointer is at the beginning of the file, and the file is truncated to zero length. If the file does not exist, attempt to create it.
w+ – Reading and writing. The file pointer is at the beginning of the file, and the file is truncated to zero length. If the file does not exist, attempt to create it.
a – Write-only. The file pointer is at the end of the file (it appends content to the file). If the file does not exist, attempt to create it.
a+ Reading and writing. The file pointer is at the end of the file. If the file doesn’t exist, attempt to create it.
Use the fread() function to read a specified number of bytes from an open file pointer. Its syntax is
The fputs() function writes to an open file pointer. Its syntax is
fputs(filepointer, content, [length]);
The file pointer must be open in order to write to the file. The length parameter is optional. If it isn’t specified, all specified content is written to the file.
Use the fclose() function to close an open file pointer. Its syntax is
Like the mkdir shell command, the mkdir() function creates a new directory on the filesystem. Its syntax is
The PHP user must have write permission in the specified directory.
As the name suggest, it attempts to give a new name to an existing file. Its syntax is
The PHP user must have permission to modify the file.
Like the rmdir shell command, the rmdir() function removes a directory from tthe filesystem. Its syntax is
The symlink() function creates a symbolic link from an existing file or directory on the filesystem to a specified link name. Its syntax is
The unlink() function delets a file from the filesystem. Its syntax is