PHP filesystem functions

feof

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;
}

file_exists

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+");
}

filesize

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.

clearstatcache

Clears cache of file status info.

copy(file, destination)

Copies file to stated destination.

delete(file)

See “unlink.”

dirname(path)

Returns the directory portion of a stated path.

disk_free_space(“/dir”)

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(mask)

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.

unlink(file)

Deletes file.

Advertisements

About samehramzylabib

See About on https://samehramzylabib.wordpress.com
This entry was posted in Coding, PHP and Filesystem and tagged . Bookmark the permalink.

Comment

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s