filesystem
//see next side dir() return an instance in the directory class Directory { string $path ; resource $handle ; string read ( void ) void rewind ( void ) void close ( void ) }
$d = dir("/etc/php5"); echo "Handle: " . $d->handle . "\n"; echo "Path: " . $d->path . "\n"; while (false !== ($entry = $d->read())) { echo $entry."\n"; } $d->close(); //closedir($dir->handle); Handle: Resource id #2 Path: /etc/php5 . .. apache cgi cli
getcwd() will default to the folder of the root script. getcwd() still points to the folder of the root script event from included files.
//
fputs()
Alias of fwrite()
is_writeable()
Alias of is_writable()
set_file_buffer()
Alias of stream_set_write_buffer() Sets the buffering for write operations on the given stream to buffer bytes. Output using fwrite() is normally buffered at 8K. This means that if there are two processes wanting to write to the same output stream (a file), each is paused after 8K of data to allow the other to write.
bool chgrp ( string $filename , mixed $group )
Attempts to change the group of the file filename to group. Only the superuser may change the group of a file arbitrarily; other users may change the group of a file to any group of which that user is a member. filename - Path to the file. group - A group name or number. Returns TRUE on success or FALSE on failure. Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem.
bool lchgrp ( string $filename , mixed $group )
Attempts to change the group of the symlink filename to group. Only the superuser may change the group of a symlink arbitrarily; other users may change the group of a symlink to any group of which that user is a member. filename - Path to the symlink. group - The group specified by name or number. Returns TRUE on success or FALSE on failure. Note: When safe mode is enabled, PHP checks whether the files or directories being operated upon have the same UID (owner) as the script that is being executed. Note: This function is not implemented on Windows platforms.
bool chmod ( string $filename , int $mode )
Attempts to change the mode of the specified file to that given in mode. filename -Path to the file. mode Note that mode is not automatically assumed to be an octal value, so strings (such as "g+w") will not work properly. To ensure the expected operation, you need to prefix mode with a zero (0):
bool chown ( string $filename , mixed $user )
Attempts to change the owner of the file filename to user user. Only the superuser may change the owner of a file. filename - Path to the file. user - A user name or number. Returns TRUE on success or FALSE on failure.
bool lchown ( string $filename , mixed $user )
Attempts to change the owner of the symlink filename to user user. Only the superuser may change the owner of a symlink. filename - Path to the file. user - User name or number. Returns TRUE on success or FALSE on failure. Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem. Note: When safe mode is enabled, PHP checks whether the files or directories being operated upon have the same UID (owner) as the script that is being executed. Note: This function is not implemented on Windows platforms.
bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )
Attempts to create the directory specified by pathname. pathname - The directory path. mode - The mode is 0777 by default, which means the widest possible access. For more information on modes, read the details on the chmod() page. mode is ignored on Windows. Note that you probably want to specify the mode as an octal number, which means it should have a leading zero. The mode is also modified by the current umask, which you can change using umask(). recursive - Allows the creation of nested directories specified in the pathname. Defaults to FALSE. context Note: Context support was added with PHP 5.0.0. For a description of contexts, refer to Stream Functions. Returns TRUE on success or FALSE on failure.
bool rmdir ( string $dirname [, resource $context ] )
Attempts to remove the directory named by dirname. The directory must be empty, and the relevant permissions must permit this. A E_WARNING level error will be generated on failure. Returns TRUE on success or FALSE on failure.
bool chdir ( string $directory )
Changes PHP's current directory to directory.
int umask ([ int $mask ] )
Changes the current 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. without arguments simply returns the current umask otherwise the old umask is returned. Usually, system default permissions for files are 666 and for directories 0777. And usually, default PHP umask is 0022 default 0666 rw-.rw-.rw- umask 0022 ---.-w-.-w- Final 0644 rw-.r--.r--
bool chroot ( string $directory )
Changes the root directory of the current process to directory, and changes the current working directory to "/". This function is only available to GNU and BSD systems, and only when using the CLI, CGI or Embed SAPI. Also, this function requires root privileges chroot("/path/to/your/chroot/"); echo getcwd() The above example will output: / Note: This function is not implemented on Windows platforms.
bool file_exists ( string $filename )
Checks whether a file or directory exists. returns TRUE if the file or directory specified by filename exists; FALSE otherwise. Note: This function will return FALSE for symlinks pointing to non-existing files. WARNING This function returns FALSE for files inaccessible due to safe mode restrictions. However these files still can be included if they are located in safe_mode_include_dir.
int pclose ( resource $handle )
Closes a file pointer to a pipe opened by popen(). handle - The file pointer must be valid, and must have been returned by a successful call to popen(). Return Values Returns the termination status of the process that was run. Example #1 pclose() example <?php $handle = popen('/bin/ls', 'r'); pclose($handle); ?>
void closedir ([ resource $dir_handle ] )
Closes the directory stream indicated by dir_handle. The stream must have previously been opened by opendir(). The directory handle resource previously opened with opendir(). If the directory handle is not specified, the last link opened by opendir() is assumed.
string tempnam ( string $dir , string $prefix )
Creates a file with a unique filename, with access permission set to 0600, in the specified directory. If the directory does not exist, it may generate a file in the system's temporary directory, and return the name of that. Returns the new temporary filename, or FALSE on failure. dir - The directory where the temporary filename will be created. prefix - The prefix of the generated temporary filename. Note: Windows uses only the first three characters of prefix
resource tmpfile ( void )
Creates a temporary file with a unique name in read-write (w+) mode and returns a file handle . Returns a file handle, similar to the one returned by fopen(), for the new file or FALSE on failure. The file is automatically removed when closed (using fclose()), or when the script ends. For details, consult your system documentation on the tmpfile(3) function, as well as the stdio.h header file.
bool unlink ( string $filename [, resource $context ] )
Deletes filename. Similar to the Unix C unlink() function. A E_WARNING level error will be generated on failure. Returns TRUE on success or FALSE on failure.
array glob ( string $pattern [, int $flags = 0 ] )
Find pathnames matching a pattern The glob() function searches for all the pathnames matching pattern according to the rules used by the libc glob() function, which is similar to the rules used by common shells. Returns an array containing the matched files/directories, an empty array if no file matched or FALSE on error. func(("*.txt") pattern The pattern. No tilde expansion or parameter substitution is done. flags GLOB_MARK - Adds a slash to each directory returned GLOB_NOSORT - Return files as they appear in the directory (no sorting) GLOB_NOCHECK - Return the search pattern if no files matching it were found GLOB_NOESCAPE - Backslashes do not quote metacharacters GLOB_BRACE - Expands {a,b,c} to match 'a', 'b', or 'c' GLOB_ONLYDIR - Return only directory entries which match the pattern GLOB_ERR - Stop on read errors (like unreadable directories), by default errors are ignored.
int fputcsv ( resource $handle , array $fields [, string $delimiter = ',' [, string $enclosure = '"' ]] )
Format line as CSV and write to file pointer Returns the length of the written string or FALSE on failure. formats a line (passed as a fields array) as CSV and write it (terminated by a newline) to the specified file handle. handle - The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()). fields - An array of values. delimiter - The optional delimiter parameter sets the field delimiter (one character only). enclosure - The optional enclosure parameter sets the field enclosure (one character only).
array stat ( string $filename )
Gathers the statistics of the file named by filename. If filename is a symbolic link, statistics are from the file itself, not the symlink.
array fstat ( resource $handle )
Gathers the statistics of the file opened by the file pointer handle. This function is similar to the stat() function except that it operates on an open file pointer instead of a filename. This function will not work on remote files as the file to be examined must be accessible via the server's filesystem Array ( [dev] => 771 [ino] => 488704 [mode] => 33188 [nlink] => 1 [uid] => 0 [gid] => 0 [rdev] => 0 [size] => 1114 [atime] => 1061067181 [mtime] => 1056136526 [ctime] => 1056136526 [blksize] => 4096 [blocks] => 8 )
array lstat ( string $filename )
Gathers the statistics of the file or symbolic link named by filename. filename - Path to a file or a symbolic link. If filename is a symbolic link, it gives you stat information about the link itself and not the data that it points to. if filename is a regular file it just returns the stat information for that file. See the manual page for stat() for information on the structure of the array that lstat() returns. This function is identical to the stat() function except that if the filename parameter is a symbolic link, the status of the symbolic link is returned, not the status of the file pointed to by the symbolic link. Example #1 Comparison of stat() and lstat() <?php symlink('uploads.php', 'uploads'); // Contrast information for uploads.php and uploads array_diff(stat('uploads'), lstat('uploads')); ?> The above example will output something similar to: Information that differs between the two files. Array ( [ino] => 97236376 [mode] => 33188 [size] => 34 [atime] => 1223580003 [mtime] => 1223581848 [ctime] => 1223581848 [blocks] => 8 ) Note: The results of this function are cached. See clearstatcache() for more details. Tip As of PHP 5.0.0, this function can also be used with some URL wrappers. Refer to List of Supported Protocols/Wrappers for a listing of which wrappers support stat() family of functionality.
array realpath_cache_size ( void )
Get the amount of memory used by the realpath cache.(PHP 5 >= 5.3.2) Return: Returns how much memory realpath cache is using. example output of a dump: int(412)
array realpath_cache_get ( void )
Get the contents of the realpath cache.(PHP 5 >= 5.3.2) Returns an array of realpath cache entries. The keys are original path entries, and the values are arrays of data items, containing the resolved path, expiration date, and other options kept in the cache. var_dump(realpath_cache_get()); The above example will output something similar to: array(2) { ["/test"]=> array(4) { ["key"]=> int(123456789) ["is_dir"]=> bool(true) ["realpath"]=> string(5) "/test" ["expires"]=> int(1260318939) } ["/test/test.php"]=> array(4) { ["key"]=> int(987654321) ["is_dir"]=> bool(false) ["realpath"]=> string(12) "/root/test.php" ["expires"]=> int(1260318939) } }
string fgetc ( resource $handle )
Gets a character from the given file pointer. handle - The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()). Returns a string containing a single character read from the file pointed to by handle. Returns FALSE on EOF. Note: This function is binary-safe. WARNING: This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.
string fgets ( resource $handle [, int $length ] )
Gets a line from file pointer. (reads length-1 characters, it includes line breaks in results) handle - The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()). Reading ends when length - 1 bytes have been read, on a newline (which is included in the return value), or on EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line. Returns a string of up to length - 1 bytes read from the file pointed to by handle. If an error occurs, returns FALSE.
array posix_getgrgid ( int $gid )
Gets information about a group provided its id. Returns: array name - The name element contains the name of the group. This is a short, usually less than 16 character "handle" of the group, not the real, full name. passwd - The passwd element contains the group's password in an encrypted format. Often, for example on a system employing "shadow" passwords, an asterisk is returned instead. gid - Group ID, should be the same as the gid parameter used when calling the function, and hence redundant. members - This consists of an array of string's for all the members in the group.
int linkinfo ( string $path )
Gets information about a link. This function is used to verify if a link (pointed to by path) really exists (using the same method as the S_ISLNK macro defined in stat.h) The device id(device that the file is on) is return. This value is the same value that is returned in a stat call. path - Path to the link. returns the st_dev field of the Unix C stat structure returned by the lstat system call. Returns 0 or FALSE in case of error. Version Description 5.3.0 This function is now available on Windows platforms (Vista, Server 2008 or greater). echo func('/vmlinuz'); // 835
array fgetcsv ( resource $handle [, int $length [, string $delimiter = ',' [, string $enclosure = '"' [, string $escape = '\\' ]]]] )
Gets line from file pointer and parse for CSV fields Similar to fgets() except that it parses the line it reads for fields in CSV format and returns an array containing the fields read. Returns an indexed array containing the fields read. handle - A valid file pointer to a file successfully opened by fopen(), popen(), or fsockopen(). length - Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters). It became optional in PHP 5. Omitting this parameter (or setting it to 0 in PHP 5.0.4 and later) the maximum line length is not limited, which is slightly slower. delimiter - Set the field delimiter (one character only). enclosure - Set the field enclosure character (one character only). escape -Set the escape character (one character only). Defaults as a backslash. Note: A blank line in a CSV file will be returned as an array comprising a single null field, and will not be treated as an error. Note: If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem. fgetcsv() returns NULL if an invalid handle is supplied or FALSE on other errors, including end of file.
int fileperms ( string $filename )
Gets permissions for the given file Returns the permissions on the file, or FALSE on failure. It returns an int such which needs to be converted to octal ex. '100777' substr(sprintf('%o', $return_value), -4); //0777
int filegroup ( string $filename )
Gets the file group. The group ID is returned in numerical format, use posix_getgrgid() to resolve it to a group name. Returns the group ID of the file, or FALSE in case of an error. The group ID is returned in numerical format, use posix_getgrgid() to resolve it to a group name. Upon failure, FALSE is returned.
int fileowner ( string $filename )
Gets the file owner Returns the user ID of the owner of the file, or FALSE on failure. The user ID is returned in numerical format, use posix_getpwuid() to resolve it to a username.
int filectime ( string $filename )
Gets the inode change time of a file. In most Unix filesystems, that is, when the permissions, owner, group, or other metadata from the inode is updated Returns the time the file was last changed, or FALSE on failure. The time is returned as a Unix timestamp. Note: In most Unix filesystems, a file is considered changed when its inode data is changed; that is, when the permissions, owner, group, or other metadata from the inode is updated. See also filemtime() (which is what you want to use when you want to create "Last Modified" footers on web pages) and fileatime(). Note: The results of this function are cached. See clearstatcache() for more details. As of PHP 5.0.0, this function can also be used with some URL wrappers. keep in mind that this function is prone to an overflow, and on big filesystems it will return negative values.
int fileatime ( string $filename )
Gets the last access time of the given file. Returns the time the file was last accessed(Read/write), or FALSE on failure. The time is returned as a Unix timestamp. Changing the inode(chmod for ex) also changes this Returns the time the file was last accessed, or FALSE on failure. The time is returned as a Unix timestamp. Note: The results of this function are cached As of PHP 5.0.0, this function can also be used with some URL wrappers.
float disk_free_space ( string $directory )
Given a string containing a directory, this function will return the number of bytes available on the corresponding filesystem or disk partition. Given a file name instead of a directory, the behaviour of the function is unspecified and may differ between operating systems and PHP versions. directory - A directory of the filesystem or disk partition Returns the number of available bytes as a float or FALSE on failure.
float disk_total_space ( string $directory )
Given a string containing a directory, this function will return the total number of bytes on the corresponding filesystem or disk partition. directory - A directory of the filesystem or disk partition. Returns the total number of bytes as a float or FALSE on failure. Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem.
string dirname ( string $path )
Given a string containing a path to a file, this function will return the name of the directory. Returns the name of the directory. If there are no slashes in path, a dot ('.') is returned, indicating the current directory. Otherwise, the returned string is path with any trailing /component removed.
string fgetss ( resource $handle [, int $length [, string $allowable_tags ]] )
Identical to fgets(), except that it attempts to strip any NUL bytes, HTML and PHP tags from the text it reads. handle - The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()). length - Length of the data to be retrieved. allowable_tags - You can use the optional third parameter to specify tags which should not be stripped. Returns a string of up to length - 1 bytes read from the file pointed to by handle, with all HTML and PHP code stripped. If an error occurs, returns FALSE.
array scandir ( string $directory [, int $sorting_order = 0 [, resource $context ]] )
List files and directories inside the specified path Returns an array of files and directories from the directory.
bool copy ( string $source , string $dest [, resource $context ] )
Makes a copy of the file source to dest. source - Path to the source file. dest - The destination path. If dest is a URL, the copy operation may fail if the wrapper does not support overwriting of existing files. WARNING--If the destination file already exists, it will be overwritten. Returns TRUE on success or FALSE on failure.
resource opendir ( string $path [, resource $context ] )
Opens up a directory handle to be used in subsequent closedir(), readdir(), and rewinddir() calls. Returns a directory handle resource on success, or FALSE on failure. 5.0.0 path supports the ftp:// URL wrapper. if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { echo "filename: $file : filetype: " . filetype($dir . $file) . "\n"; } closedir($dh); } }
int fpassthru ( resource $handle )
Output all remaining data on a file pointer Reads to EOF on the given file pointer from the current position and writes the results to the output buffer. (pointer opened with w mode does not seem to work) You may need to call rewind() to reset the file pointer to the beginning of the file if you have already written data to the file. If you just want to dump the contents of a file to the output buffer, without first modifying it or seeking to a particular offset, you may want to use the readfile(), which saves you the fopen() call. If an error occurs, fpassthru() returns FALSE. Otherwise, fpassthru() returns the number of characters read from handle and passed through to the output. Note: When using fpassthru() on a binary file on Windows systems, you should make sure to open the file in binary mode by appending a b to the mode used in the call to fopen(). You are encouraged to use the b flag when dealing with binary files, even if your system does not require it, so that your scripts will be more portable.
int readfile ( string $filename [, bool $use_include_path = false [, resource $context ]] )
Reads a file and writes it to the output buffer. Returns the number of bytes read from the file. If an error occurs, FALSE is returned and unless the function was called as @readfile(), an error message is printed.
array file ( string $filename [, int $flags = 0 [, resource $context ]] )
Reads an entire file into an array. A URL can be used as a filename with this function if the fopen wrappers have been enabled. flags - The optional parameter flags can be one, or more, of the following constants: FILE_USE_INCLUDE_PATH Search for the file in the include_path. FILE_IGNORE_NEW_LINES Do not add newline at the end of each array element FILE_SKIP_EMPTY_LINES Skip empty lines Returns the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached. Upon failure, file() returns FALSE.
string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen = -1 ]]]] )
Reads entire file into a string This function is similar to file(), except that it returns the file in a string, starting at the specified offset up to maxlen bytes. On failure, it will return FALSE. it is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance. Note: If you're opening a URI with special characters, such as spaces, you need to encode the URI with urlencode(). Note:The default value of maxlen is not actually -1; rather, it is an internal PHP value which means to copy the entire stream until end-of-file is reached. The only way to specify this default value is to leave it out of the parameter list. filename - Name of the file to read. use_include_path - As of PHP 5 the FILE_USE_INCLUDE_PATH can be used to trigger include path search. context - A valid context resource created with stream_context_create(). If you don't need to use a custom context, you can skip this parameter by NULL. offset - The offset where the reading starts on the original stream. maxlen - Maximum length of data read. The default is to read until end of file is reached. Note that this parameter is applied to the stream processed by the filters.
bool rename ( string $oldname , string $newname [, resource $context ] )
Renames a file or directory Returns TRUE on success or FALSE on failure.
void rewinddir ([ resource $dir_handle ] )
Resets the directory stream indicated by dir_handle to the beginning of the directory. dir_handle -- The directory handle resource previously opened with opendir(). If the directory handle is not specified, the last link opened by opendir() is assumed.
array posix_getpwuid ( int $uid )
Returns an array of information about the user referenced by the given user ID. name - The name element contains the username of the user. This is a short, usually less than 16 character "handle" of the user, not the real, full name. passwd - The passwd element contains the user's password in an encrypted format. Often, for example on a system employing "shadow" passwords, an asterisk is returned instead. uid - User ID, should be the same as the uid parameter used when calling the function, and hence redundant. gid - The group ID of the user. Use the function posix_getgrgid() to resolve the group name and a list of its members. gecos - GECOS is an obsolete term that refers to the finger information field on a Honeywell batch processing system. The field, however, lives on, and its contents have been formalized by POSIX. The field contains a comma separated list containing the user's full name, office phone, office number, and home phone number. On most systems, only the user's full name is available. dir - This element contains the absolute path to the home directory of the user. shell - The shell element contains the absolute path to the executable of the user's default shell.
string basename ( string $path [, string $suffix ] )
Returns filename component of path suffix - If the filename ends in suffix this will also be cut off
string readdir ([ resource $dir_handle ] )
Returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem. Only 1 file is read with each call. Returns the filename on success or FALSE on failure.
int fileinode ( string $filename )
Returns the inode number of the file, or FALSE on failure.
string sys_get_temp_dir ( void )
Returns the path of the directory PHP stores temporary files in by default.
int ftell ( resource $handle )
Returns the position of the file pointer referenced by handle as an integer; i.e., its offset into the file stream. If an error occurs, returns FALSE
int filesize ( string $filename )
Returns the size of the file in bytes, or FALSE (and generates an error of level E_WARNING) in case of an error. Note: Because PHP's integer type is signed and many platforms use 32bit integers, filesize() may return unexpected results for files which are larger than 2GB. For files between 2GB and 4GB in size this can usually be overcome by using sprintf("%u", filesize($file)). Note: The results of this function are cached. As of PHP 5.0.0, this function can also be used with some URL wrappers.
int filemtime ( string $filename )
Returns the time the file was last modified, or FALSE on failure. The time is returned as a Unix timestamp, which is suitable for the date() function. This function returns the time when the data blocks of a file were being written to, that is, the time when the content of the file was changed. As of PHP 5.0.0, this function can also be used with some URL wrapper
string filetype ( string $filename )
Returns the type of the file. Possible values are fifo, char, dir, block, link, file, socket and unknown. Returns FALSE if an error occurs. filetype() will also produce an E_NOTICE message if the stat call fails or if the file type is unknown. As of PHP 5.0.0, this function can also be used with some URL wrappers. Note: The results of this function are cached.
bool touch ( string $filename [, int $time = time() [, int $atime ]] )
Sets access and modification time of file If the file does not exist, it will be created. Note that the access time is always modified, regardless of the number of parameters. Returns TRUE on success or FALSE on failure.
bool rewind ( resource $handle )
Sets the file position indicator for handle to the beginning of the file stream. Returns TRUE on success or FALSE on failure. Note: If you have opened the file in append ("a" or "a+") mode, any data you write to the file will always be appended, regardless of the file position.
int fseek ( resource $handle , int $offset [, int $whence = SEEK_SET ] )
Sets the file position indicator for the file referenced by handle. The new position, measured in bytes from the beginning of the file, is obtained by adding offset to the position specified by whence. Upon success, returns 0; otherwise, returns -1. Note that seeking past EOF is not considered an error handle - A file system pointer resource that is typically created using fopen(). offset - The offset. To move to a position before the end-of-file, you need to pass a negative value in offset and set whence to SEEK_END. whence: SEEK_SET - Set position equal to offset bytes. SEEK_CUR - Set position to current location plus offset. SEEK_END - Set position to end-of-file plus offset.
bool ftruncate ( resource $handle , int $size )
Takes the filepointer, handle, and truncates the file to length, size. Returns TRUE on success or FALSE on failure. Note: If size is larger than the file then the file is extended with null bytes. If size is smaller than the file then the file is truncated to that sizeNote: The handle must be open for writing.
bool is_readable ( string $filename )
Tells whether a file exists and is readable. Returns TRUE if the file or directory specified by filename exists and is readable, FALSE otherwise.
bool is_uploaded_file ( string $filename )
Tells whether the file was uploaded via HTTP POST Returns TRUE on success or FALSE on failure. Returns TRUE if the file named by filename was uploaded via HTTP POST. This is useful to help ensure that a malicious user hasn't tried to trick the script into working on files upon which it should not be working--for instance, /etc/passwd. This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system. For proper working, the function is_uploaded_file() needs an argument like $_FILES['userfile']['tmp_name'], - the name of the uploaded file on the clients machine $_FILES['userfile']['name'] does not work. <?php if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n"; echo "Displaying contents\n"; readfile($_FILES['userfile']['tmp_name']); } else { echo "Possible file upload attack: "; echo "filename '". $_FILES['userfile']['tmp_name'] . "'."; } ?>
bool is_link ( string $filename )
Tells whether the filename is a symbolic link Returns TRUE if the filename exists and is a symbolic link, FALSE otherwise.
bool is_executable ( string $filename )
Tells whether the filename is executable. Returns TRUE if the filename exists and is executable, or FALSE on error. 5.0.0 - is_executable() became available with Windows
bool is_writable ( string $filename )
Tells whether the filename is writable Returns TRUE if the filename exists and is writable. The filename argument may be a directory name allowing you to check if a directory is writable. Keep in mind that PHP may be accessing the file as the user id that the web server runs as (often 'nobody'). Safe mode limitations are not taken into account.
bool is_file ( string $filename )
Tells whether the given file is a regular file. Returns TRUE if the filename exists and is a regular file, FALSE otherw
bool is_dir ( string $filename )
Tells whether the given filename is a directory. Returns TRUE if the filename exists and is a directory, FALSE otherwise. If filename is a relative filename, it will be checked relative to the current working directory. If filename is a symbolic or hard link then the link will be resolved and checked. If you have enabled safe mode, or open_basedir further restrictions may apply. var_dump(is_dir('..')); //one dir up
bool feof ( resource $handle )
Tests for end-of-file on a file pointer. handle - The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()). Returns TRUE if the file pointer is at EOF or an error occurs (including socket timeout); otherwise returns FALSE. WARNING-If the passed file pointer is not valid you may get an infinite loop, because feof() fails to return TRUE.
bool fclose ( resource $handle )
The file pointed to by handle is closed The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen(). Returns TRUE on success or FALSE on failure. $handle = fopen('somefile.txt', 'r'); function($handle);
bool move_uploaded_file ( string $filename , string $destination )
This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination. This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system. filename - The filename of the uploaded file. destination -The destination of the moved file. Returns If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE. If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued. Example #1 Uploading multiple files <?php $uploads_dir = '/uploads'; foreach ($_FILES["pictures"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; $name = $_FILES["pictures"]["name"][$key]; move_uploaded_file($tmp_name, "$uploads_dir/$name"); } } ?> Warning If the destination file already exists, it will be overwritten.
bool fflush ( resource $handle )
This function forces a write of all buffered output to the resource pointed to by the file handle. handle - The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()). Returns TRUE on success or FALSE on failure. $file1=fopen("c:/rose1/ram.txt","r"); //some file updation code //finally update the data into file using the fflush() function fflush($file1);
diskfreespace()
This function is an alias of: disk_free_space().
int file_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] )
This function is identical to calling fopen(), fwrite() and fclose() successively to write data to a file. If filename does not exist, the file is created. Otherwise, the existing file is overwritten, unless the FILE_APPEND flags is set. filename - Path to the file where to write the data. data - The data to write. Can be either a string, an array or a stream resource. If data is a stream resource, the remaining buffer of that stream will be copied to the specified file. This is similar with using stream_copy_to_stream(). You can also specify the data parameter as a single dimension array. This is equivalent to file_put_contents($filename, implode('', $array)). The function returns the number of bytes that were written to the file, or FALSE on failure.
void delete ( void )
This is a dummy manual entry to satisfy those people who are looking for unlink() or unset() in the wrong place.
void clearstatcache ([ bool $clear_realpath_cache = false [, string $filename ]] )
When you use stat(), lstat(), or any of the other functions listed in the affected functions list (below), PHP caches the information those functions return in order to provide faster performance. However, in certain cases, you may want to clear the cached information. For instance, if the same file is being checked multiple times within a single script, and that file is in danger of being removed or changed during that script's operation, you may elect to clear the status cache clear_realpath_cache - Whether to clear the realpath cache or not. filename - Clear the realpath cache for a specific filename; only used if clear_realpath_cache is TRUE. Affected functions include stat(), lstat(), file_exists(), is_writable(), is_readable(), is_executable(), is_file(), is_dir(), is_link(), filectime(), fileatime(), filemtime(), fileinode(), filegroup(), fileowner(), filesize(), filetype(), and fileperm
bool flock ( resource $handle , int $operation [, int &$wouldblock ] )
allows you to perform a simple reader/writer model which can be used on virtually every platform (including most Unix derivatives and even Windows). On versions of PHP before 5.3.2, the lock is released also by fclose() (which is also called automatically when script finished). PHP supports a portable way of locking complete files in an advisory way (which means all accessing programs have to use the same way of locking or it will not work). By default, this function will block until the requested lock is acquired; this may be controlled (on non-Windows platforms) with the LOCK_NB option documented below. handle - A file system pointer resource that is typically created using fopen(). operation is one of the following: LOCK_SH to acquire a shared lock (reader). LOCK_EX to acquire an exclusive lock (writer). LOCK_UN to release a lock (shared or exclusive). It is also possible to add LOCK_NB as a bitmask to one of the above operations if you don't want flock() to block while locking. (not supported on Windows) wouldblock - The optional third argument is set to TRUE if the lock would block (EWOULDBLOCK errno condition). (not supported on Windows) Returns TRUE on success or FALSE on failure. Because flock() requires a file pointer, you may have to use a special lock file to protect access to a file that you intend to truncate by opening it in write mode (with a "w" or "w+" argument to fopen()). May only be used on file pointers returned by fopen() for local files, or file pointers pointing to userspace streams that implement the streamWrapper::stream_lock() method On some operating systems flock() is implemented at the process level. When using a multithreaded server API like ISAPI you may not be able to rely on flock() to protect files against other PHP scripts running in parallel threads of the same server instance! if(flock($fp, LOCK_EX | LOCK_NB)) { echo 'lock obtained'; flock($fp, LOCK_UN); }
array parse_ini_string ( string $ini [, bool $process_sections = false [, int $scanner_mode = INI_SCANNER_NORMAL ]] )
returns the settings in the ini string in an associative array.(PHP 5 >= 5.3.0) The structure of the ini string is the same as the php.ini's. ini - The contents of the ini file being parsed. process_sections - By setting the process_sections parameter to TRUE, you get a multidimensional array, with the section names and settings included. The default for process_sections is FALSE scanner_mode - Can either be INI_SCANNER_NORMAL (default) or INI_SCANNER_RAW. If INI_SCANNER_RAW is supplied, then option values will not be parsed. The settings are returned as an associative array on success, and FALSE on failure. Note: There are reserved words which must not be used as keys for ini files. These include: null, yes, no, true, false, on, off, none. Values null, no and false results in "", yes and true results in "1". Characters {}|&~![()^" must not be used anywhere in the key and have a special meaning in the value.
mixed fscanf ( resource $handle , string $format [, mixed &$... ] )
similar to sscanf(), but it takes its input from a file associated with handle and interprets the input according to the specified format, which is described in the documentation for sprintf(). Any whitespace in the format string matches any whitespace in the input stream. This means that even a tab \t in the format string can match a single space character in the input stream. Each call to it reads one line from the file. If only two parameters were passed to this function, the values parsed will be returned as an array. Otherwise, if optional parameters are passed, the function will return the number of assigned values. The optional parameters must be passed by reference. Required. Specifies the format. Possible format values: The interpreted format for str, which is described in the documentation for sprintf() with following differences: Function is not locale-aware. F, g, G and b are not supported. D stands for decimal number(DOES NOT SEEM TO WORK for floats). %f works for float %D, %d, %i works for integer i stands for integer with base detection. n stands for number of characters processed so far.
string readlink ( string $path )
returns the filename being pointed to by a symbolic link path - The symbolic link path. this function does the same as the readlink C function. Version Description 5.3.0 This function is now available on Windows platforms (Vista, Server 2008 or greater). Return: Returns the contents of the symbolic link path or FALSE on error.
resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )
binds a named resource, specified by filename, to a stream. Returns a file pointer resource on success, or FALSE on error. If filename is of the form "scheme://...", it is assumed to be a URL and PHP will search for a protocol handler (also known as a wrapper) for that scheme. If no wrappers for that protocol are registered, PHP will emit a notice to help you track potential problems in your script and then continue as though filename specifies a regular file. If PHP has decided that filename specifies a local file, then it will try to open a stream on that file. The file must be accessible to PHP, so you need to ensure that the file access permissions allow this access. If you have enabled safe mode, or open_basedir further restrictions may apply. If PHP has decided that filename specifies a registered protocol, and that protocol is registered as a network URL, PHP will check to make sure that allow_url_fopen is enabled. If it is switched off, PHP will emit a warning and the fopen call will fail. On the Windows platform, be careful to escape any backslashes used in the path to the file, or use forward slashes. Windows offers a text-mode translation flag ('t') which will transparently translate \n to \r\n when working with the file. In contrast, you can also use 'b' to force binary mode, which will not translate your data. To use these flags, specify either 'b' or 't' as the last character of the mode parameter. For portability, it is strongly recommended that you always use the 'b' flag when opening files with fopen()
bool fnmatch ( string $pattern , string $string [, int $flags = 0 ] )
checks if the passed string would match the given shell wildcard pattern. pattern - The shell wildcard pattern. string - The tested string. This function is especially useful for filenames, but may also be used on regular strings. function("*gr[ae]y", $color) The average user may be used to shell patterns or at least in their simplest form to '?' and '*' wildcards so using fnmatch() instead of preg_match() for frontend search expression input may be way more convenient for non-programming users The value of flags can be any combination of the following flags, joined with the binary OR (|) operator. A list of possible flags for fnmatch() Flag Description FNM_NOESCAPE - Disable backslash escaping. FNM_PATHNAME - Slash in string only matches slash in the given pattern. FNM_PERIOD Leading period in string must be exactly matched by period in the given pattern. FNM_CASEFOLD Caseless match. Part of the GNU extension.
bool link ( string $from_path , string $to_path )
creates a hard link. from_path - The link name. to_path - Target of the link. Returns TRUE on success or FALSE on failure. In linux hard linking to a directory is not permitted. Note: For Windows only: This function requires PHP to run in an elevated mode or with the UAC disabled. 5.3.0 This function is now available on Windows platforms (Vista, Server 2008 or greater).
bool symlink ( string $target , string $link )
creates a symbolic link to the existing target with the specified name link. Returns TRUE on success or FALSE on failure.
array parse_ini_file ( string $filename [, bool $process_sections = false [, int $scanner_mode = INI_SCANNER_NORMAL ]] )
loads in the ini file specified in filename, and returns the settings in it in an associative array. (php >= 5.3.0) The structure of the ini file is the same as the php.ini's. filename - The filename of the ini file being parsed. process_sections - By setting the process_sections parameter to TRUE, you get a multidimensional array, with the section names and settings included. The default for process_sections is FALSE scanner_mode -Can either be INI_SCANNER_NORMAL (default) or INI_SCANNER_RAW. If INI_SCANNER_RAW is supplied, then option values will not be parsed. Return: The settings are returned as an associative array on success, and FALSE on failure. Version Description 5.3.0 Added optional scanner_mode parameter. Single quotes may now be used around variable assignments. Hash marks (#) may no longer be used as comments and will throw a deprecation warning if used. 5.2.7 On syntax error this function will return FALSE rather then an empty array. 5.2.4 Keys and section names consisting of numbers are now evaluated as PHP integers thus numbers starting by 0 are evaluated as octals and numbers starting by 0x are evaluated as hexadecimals. 5.0.0 Values enclosed in double quotes can contain new lines. 4.2.1 This function is now affected by safe mode and open_basedir.
resource popen ( string $command , string $mode )
opens a pipe to a process executed by forking the command given by command. command - The command mode - The mode Return: Returns a file pointer identical to that returned by fopen(), except that it is unidirectional (may only be used for reading or writing) and must be closed with pclose(). This pointer may be used with fgets(), fgetss(), and fwrite(). If an error occurs, returns FALSE. $handle = popen("/bin/ls", "r"); If the command to be executed could not be found, a valid resource is returned. This may seem odd, but makes sense; it allows you to access any error message returned by the shell: If you're looking for bi-directional support (two-way), use proc_open(). Note: When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not allowed to have .. components in the path to the executable.
string fread ( resource $handle , int $length )
reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read EOF (end of file) is reached a packet becomes available (for network streams) 8192 bytes have been read (after opening userspace stream) When reading from anything that is not a regular local file, such as streams returned when reading remote files or from popen() and fsockopen(), reading will stop after a packet is available. This means that you should collect the data together in chunks as shown in the examples below. <?php $handle = fopen("http://www.example.com/", "rb"); $contents = ''; while (!feof($handle)) { $contents .= fread($handle, 8192); } fclose($handle); ?> If you just want to get the contents of a file into a string, use file_get_contents() as it has much better performance than the code above. Note that fread() reads from the current position of the file pointer. Use ftell() to find the current position of the pointer and rewind() to rewind the pointer position.
mixed pathinfo ( string $path [, int $options = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME ]
returns an associative array containing information about a path. array(4) { ["dirname"]=> string(10) "mydir/text" ["basename"]=> string(8) "book.txt" ["extension"]=> string(3) "txt" ["filename"]=> string(4) "book" }