www.pickatutorial.com Computer Tutorials
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons PHP File System Functions Bookmark and Share
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
PHP's built-in file system functions could prove to be really powerful tools for every serious PHP web programmer, provided that they are used correctly. We must take extra care when using file system functions.

chmod(), chgrp(), and chown()
All of the above three functions are used to modify the permissions, group and the owner of the argument file or directory. Their syntax follows:

chmod("filename", mode);
chmgrp("filename", newgroup);
chown("filename", newowner);

copy()
We use the copy() function to copy a file. It requires a filename and a destination path in order to copy a file. Its syntax follows:

copy("source file", "destination");

fopen() This function is used to open a specified file for reading or writing or a URL for reading only. Its syntax follows:

fopen("filename", "mode")

The specified mode determines whether the file is opened for reading, writing, or both. The following table lists and describes the values the mode argument can take:
Mode Description
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 (it appends content to the file). If the file does not exist, attempt to create it.
x Create and open a file for writing only. The file pointer is at the beginning of the file. This will fail if the file already exists.
x+ Create and open a file for reading and writing. The file pointer is at the beginning of the file. This will fail if the file already exists.

fread()
This function is used to read a specified number of bytes from an open file pointer. Its syntax follows:

fread(filepointer, length);

fputs()
This function is used to write to an open file pointer. Its syntax follows:

fputs(filepointer, content, [length]);

fclose()
We use the fclose() function to close an open file pointer. Its syntax follows:

fclose(filepointer);

mkdir()
This function creates a new directory in the file system. Its syntax follows:

mkdir("pathname", mode);

rename()

This function is used to rename an existing file. Its syntax follows:

rename("oldname", "newname");

rmdir()

This function is used to remove an existing directory form the file system. Its syntax follows:

rmdir("pathname");

unlink()
This function is used to delete a file from the file system. Its syntax follows:

unlink("filename");
Our PHP MySQL Programming Tutorial for Web Developers ends here. How did you find it? Please let us know at pickatutorial@yahoo.com | Tutorial author: farooq_fl@yahoo.com

More PHP MySQL Programming Tutorials

Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.