PHP Function: Built-in Functions part 5

Welcome back to Built-in Functions.

Filesytem 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:

chmod(“filename”, mode);
chmgrp(“filename”, newsgroup);
chown(“filename”, newowner);
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.

copy() 
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.
fopen() 
The fopen() function opens a specified file or URL for reading and/or writing. The syntax of fopen() is
fopen(“filename”, “mode”) 
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.

fread() 
Use the fread() function to read a specified number of bytes from an open file pointer. Its syntax is
fread(filepointer, length);
fputs()
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.
fclose() 
Use the fclose() function to close an open file pointer. Its syntax is
fclose(filepointer);
mkdir() 
Like the mkdir shell command, the mkdir() function creates a new directory on the filesystem. Its syntax is
mkdir(“pathname”, mode); 
The PHP user must have write permission in the specified directory.
rename()
As the name suggest, it attempts to give a new name to an existing file. Its syntax is
rename(“oldname”, “newname”);
The PHP user must have permission to modify the file.
rmdir() 
Like the rmdir shell command, the rmdir() function removes a directory from tthe filesystem. Its syntax is
rmdir(“pathname”)
symlink() 
The symlink() function creates a symbolic link from an existing file or directory on the filesystem to a specified link name. Its syntax is
symlink(“targetname”, “linkname”);
unlink() 
The unlink() function delets a file from the filesystem. Its syntax is
unlink(“filesystem”);

Next php function: Built-in Functions part 6