PHP filesystem functions


The feof function tests for end-of-file on a file pointer. In this example it’s used in a while loop to perform the same function on each line in a file:

while (!feof($fD)) {
  $aLine = fgets($fD, 5000);
  echo $aLine;


The function returns true if the file exists, false if not found. The results of this test are stored in a cache, which may be cleared by use of the function clearstatcache().

if (!file_exists("testfile.php")) {
  $fd = fopen("testfile.php", "w+");


returns and caches the size of a file in bytes.

basename (filepath, [suffix])

returns the filename portion of a stated path.

chmod(file, mode)

Changes to the stated octal mode.


Clears cache of file status info.

copy(file, destination)

Copies file to stated destination.


See “unlink.”


Returns the directory portion of a stated path.


Returns the number of free bytes in a given directory.

fgetcsv(fp, length, delimiter [, enclosure])

Reads in a line and parses for CSV format.

fgetss(fp, length [, allowable_tags])

Gets a file line (delimited by a newline character) and strips all HTML and PHP tags except those specifically allowed.

rename(oldname, newname)

Renames file.

touch(file, [time])

Sets modification time; creates file if it does not exist.


umask() sets PHP’s umask to mask & 0777 and returns the old umask. When PHP is being used as a server module, the umask is restored when each request is finished.


Deletes file.


About samehramzylabib

See About on
This entry was posted in Coding, PHP and Filesystem and tagged . Bookmark the permalink.


Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s