MENU
General Files
file_exists($s) returns true if the file or directory $s exists. is_file($s) returns true if $s is a regular file. is_executable($s) returns true if $s is an executable file. is_link($s) returns true if $s is a symbolic link. is_readable($s) returns true if $s is a readable file. is_writable($s) or is_writeable ($s) returns true if $s is a writable file.fnmatch($s1,$s2[,$i]) returns true if the passed string $s2 matches the shell wildcard pattern $s1. $i can be any combination of:
FNM_NOESCAPE | Disable backslash escaping. |
FNM_PATHNAME | A slash in the string only matches a slash in the given pattern. |
FNM_PERIOD | A leading period in the string must be exactly matched by a period in the given pattern. |
FNM_CASEFOLD | Caseless match. |
glob($s[,$i]) returns an array of pathnames matching the shell wildcard pattern $s. $i can be:
GLOB_MARK | Adds a slash to each directory returned. |
GLOB_NOSORT | No sorting. |
GLOB_NOCHECK | Returns the search pattern if no matching files were found. |
GLOB_NOESCAPE | Backslashes do not quote metacharacters. |
GLOB_BRACE | Expands {a,b,c} to match ‘a’,’b’ or ’c’. |
GLOB_ONLYDIR | Returns only matching directories. |
GLOB_ERR | Stops on read errors. |
<!DOCTYPE html><html><head></head>
<body><?php
var_dump(fnmatch("a?c","abc")); // true
var_dump(fnmatch("*A",".CBA")); // true
var_dump(fnmatch("*A",".CBA",FNM_PERIOD)); //false
var_dump(fnmatch("[abc]","B",FNM_CASEFOLD)); //true
echo "<br /><br />";
print_r(glob("*",GLOB_MARK|GLOB_NOSORT));
?></body></html>
bool(true) bool(true) bool(false) bool(true) Array ( [0] => action.php [1] => alpha_beta.php [2] => apache_pb.gif [3] => apache_pb.png [4] => apache_pb2.gif [5] => apache_pb2.png [6] => apache_pb2_ani.gif [7] => bar.php [8] => error.txt [9] => favicon.ico [10] => foo.php [11] => forbidden\ [12] => index.html [13] => intro.php [14] => restricted\ [15] => submit.gif [16] => test.php [17] => testing2\ [18] => upload\ [19] => upload.php [20] => upload_file.php [21] => xampp\ )
filesize($s) returns the size of the file $s. filetype($s) returns the type of the file $s, which can be “fifo”,”char”,”dir”,”block”,”link”,”file”,”socket” and “unknown”.
stat($s) returns an array containing information about a file $s. fstat($r) is similar to stat() except that it operates on an open file pointer $r. lstat($s) is similar to stat() except that if the file $s is a symbolic link, the status of the symbolic link is returned.
clearstatcache([$b=false[,$s]]) clears the file status cache. When you call a function that returns information about a file, PHP often caches it to provide faster performance. In case the file is changed, the cache needs to be cleared in order to reflect the reality. If $b is true, the realpath cache is cleared. If $s is set, the realpath and stat cache are cleared for the file $s only.
<!DOCTYPE html><html><head></head>
<body><?php
print_r(stat("test.php")); echo "<br />";
echo fileatime("test.php")."<br />";
touch("test.php");
echo fileatime("test.php")."<br />";
clearstatcache();
echo fileatime("test.php")."<br />";
?></body></html>
Array ( [0] => 4 [1] => 0 [2] => 33206 [3] => 1 [4] => 0 [5] => 0 [6] => 4 [7] => 310 [8] => 1365504496 [9] => 1365504496 [10] => 1352526964 [11] => -1 [12] => -1 [dev] => 4 [ino] => 0 [mode] => 33206 [nlink] => 1 [uid] => 0 [gid] => 0 [rdev] => 4 [size] => 310 [atime] => 1365504496 [mtime] => 1365504496 [ctime] => 1352526964 [blksize] => -1 [blocks] => -1 ) 1365504496 1365504496 1365504517
chmod($s,$i) changes the permission mode of the file $s to $i. $i consists of three octal number components for the owner, the user group, and everybody else, in this order. One component can be computed by adding up the needed permissions for that target user base. Number 1 means execution rights, number 2 means writeable rights, number 4 means readable rights. Add up these numbers to specify the needed rights. fileperms($s) returns the permissions for the file $s, along with other information. Lower bits are the same as the permissions expected by chmod().
umask([$i]) sets PHP’s umask to $i & 0777 and returns the old umask. Without any arguments, it simply returns the current umask.
RESETRUNFULL
<!DOCTYPE html><html><head></head>
<body><?php
echo sprintf("%o",fileperms("test.php"))."<br />";
chmod("test.php",0764);
?></body></html>
tempnam($s1,$s2) creates a file with a unique filename, with the prefix $s2 and access permission set to 0600, in the specified directory $s1. It returns the new temporary filename, or FALSE on failure. tmpfile() creates a temporary file with a unique name in read-write mode and returns the file handle. The file is automatically closed when the script ends.
is_uploaded_file($s) returns true if the file $s was uploaded via HTTP POST. move_uploaded_file ($s1,$s2) moves an uploaded file $s1 to $s2.
parse_ini_file($s[,$b=false[,$i=INI_SCANNER_NORMAL]]) returns an array consisting of the settings in the ini file $s. If $b is set to true, you get a multidimensional array, with the section names included. If $i is set to INI_SCANNER_RAW, then option values will not be parsed. parse_ini_ string(……) is similar but takes in a string $s instead of a file.
<!DOCTYPE html><html><head></head>
<body><?php
$tmp = tempnam(".","TEST");
copy($tmp,"TESTING");
unlink($tmp);
unlink("TESTING");
$ini = "
[SECTION 1]
a=123;
b=456";
print_r(parse_ini_string($ini));
echo "<br />";
print_r(parse_ini_string($ini,true));
?></body></html>
Array ( [a] => 123 [b] => 456 ) Array ( [SECTION 1] => Array ( [a] => 123 [b] => 456 ) )