= PHP_4_1_0, PHP_5, PHP_7, PHP_8
// ============================== USING FUNCTIONS (83)
// basename() - PHP_4, PHP_5, PHP_7, PHP_8
// chgrp() - PHP_4, PHP_5, PHP_7, PHP_8
// chmod() - PHP_4, PHP_5, PHP_7, PHP_8
// chown() - PHP_4, PHP_5, PHP_7, PHP_8
// clearstatcache() - PHP_4, PHP_5, PHP_7, PHP_8
// copy() - PHP_4, PHP_5, PHP_7, PHP_8
// delete - unlink()
// dirname() - PHP_4, PHP_5, PHP_7, PHP_8
// disk_free_space() - PHP_4 >= PHP_4_1_0, PHP_5, PHP_7, PHP_8
// disk_total_space() - PHP_4 >= PHP_4_1_0, PHP_5, PHP_7, PHP_8
// diskfreespace() - PHP_4, PHP_5, PHP_7, PHP_8
// fclose() - PHP_4, PHP_5, PHP_7, PHP_8
// OFFLINE | fdatasync() - PHP_8 >= PHP_8_1_0
// feof() - PHP_4, PHP_5, PHP_7, PHP_8
// fflush() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8
// fgetc() - PHP_4, PHP_5, PHP_7, PHP_8
// fgetcsv() - PHP_4, PHP_5, PHP_7, PHP_8
// fgets() - PHP_4, PHP_5, PHP_7, PHP_8
// OFFLINE | fgetss() - PHP_4, PHP_5, PHP_7
// file_exists() - PHP_4, PHP_5, PHP_7, PHP_8
// file_get_contents() - PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8
// OFFLINE | file_put_contents() - PHP_5, PHP_7, PHP_8
// file() - PHP_4, PHP_5, PHP_7, PHP_8
// fileatime() - PHP_4, PHP_5, PHP_7, PHP_8
// filectime() - PHP_4, PHP_5, PHP_7, PHP_8
// filegroup() - PHP_4, PHP_5, PHP_7, PHP_8
// fileinode() - PHP_4, PHP_5, PHP_7, PHP_8
// filemtime() - PHP_4, PHP_5, PHP_7, PHP_8
// fileowner() - PHP_4, PHP_5, PHP_7, PHP_8
// fileperms() - PHP_4, PHP_5, PHP_7, PHP_8
// filesize() - PHP_4, PHP_5, PHP_7, PHP_8
// filetype() - PHP_4, PHP_5, PHP_7, PHP_8
// flock() - PHP_4, PHP_5, PHP_7, PHP_8
// fnmatch() - PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8
// fopen() - PHP_4, PHP_5, PHP_7, PHP_8
// fpassthru() - PHP_4, PHP_5, PHP_7, PHP_8
// OFFLINE | fputcsv() - PHP_5 >= PHP_5_1_0, PHP_7, PHP_8
// fputs() - PHP_4, PHP_5, PHP_7, PHP_8
// fread() - PHP_4, PHP_5, PHP_7, PHP_8
// fscanf() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8
// fseek() - PHP_4, PHP_5, PHP_7, PHP_8
// fstat() - PHP_4, PHP_5, PHP_7, PHP_8
// OFFLINE | fsync() - PHP_8 >= PHP_8_1_0
// ftell() - PHP_4, PHP_5, PHP_7, PHP_8
// ftruncate() - PHP_4, PHP_5, PHP_7, PHP_8
// fwrite() - PHP_4, PHP_5, PHP_7, PHP_8
// glob() - PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8
// is_dir() - PHP_4, PHP_5, PHP_7, PHP_8
// is_executable() - PHP_4, PHP_5, PHP_7, PHP_8
// is_file() - PHP_4, PHP_5, PHP_7, PHP_8
// is_link() - PHP_4, PHP_5, PHP_7, PHP_8
// is_readable() - PHP_4, PHP_5, PHP_7, PHP_8
// is_uploaded_file() - PHP_4 >= PHP_4_0_3, PHP_5, PHP_7, PHP_8
// is_writable() - PHP_4, PHP_5, PHP_7, PHP_8
// is_writeable() - PHP_4, PHP_5, PHP_7, PHP_8
// OFFLINE | lchgrp() - PHP_5 >= PHP_5_1_3, PHP_7, PHP_8
// OFFLINE | lchown() - PHP_5 >= PHP_5_1_3, PHP_7, PHP_8
// link() - PHP_4, PHP_5, PHP_7, PHP_8
// linkinfo() - PHP_4, PHP_5, PHP_7, PHP_8
// lstat() - PHP_4, PHP_5, PHP_7, PHP_8
// mkdir() - PHP_4, PHP_5, PHP_7, PHP_8
// move_uploaded_file() - PHP_4 >= PHP_4_0_3, PHP_5, PHP_7, PHP_8
// parse_ini_file() - PHP_4, PHP_5, PHP_7, PHP_8
// OFFLINE | parse_ini_string() - PHP_5 >= PHP_5_3_0, PHP_7, PHP_8
// pathinfo() - PHP_4 >= PHP_4_0_3, PHP_5, PHP_7, PHP_8
// pclose() - PHP_4, PHP_5, PHP_7, PHP_8
// popen() - PHP_4, PHP_5, PHP_7, PHP_8
// readfile() - PHP_4, PHP_5, PHP_7, PHP_8
// readlink() - PHP_4, PHP_5, PHP_7, PHP_8
// OFFLINE | realpath_cache_get() - PHP_5 >= PHP_5_3_2, PHP_7, PHP_8
// OFFLINE | realpath_cache_size() - PHP_5 >= PHP_5_3_2, PHP_7, PHP_8
// realpath() - PHP_4, PHP_5, PHP_7, PHP_8
// rename() - PHP_4, PHP_5, PHP_7, PHP_8
// rewind() - PHP_4, PHP_5, PHP_7, PHP_8
// rmdir() - PHP_4, PHP_5, PHP_7, PHP_8
// set_file_buffer() - PHP_4, PHP_5, PHP_7, PHP_8
// stat() - PHP_4, PHP_5, PHP_7, PHP_8
// symlink() - PHP_4, PHP_5, PHP_7, PHP_8
// tempnam() - PHP_4, PHP_5, PHP_7, PHP_8
// tmpfile() - PHP_4, PHP_5, PHP_7, PHP_8
// touch() - PHP_4, PHP_5, PHP_7, PHP_8
// umask() - PHP_4, PHP_5, PHP_7, PHP_8
// unlink() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== USING DATA_TYPES (10)
// array
// string
// bool
// int
// void
// resource
// float
// false
// mixed
// null
// ============================== END
// REQUIREMENTS
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM
// ============================== ABOUT
// PHP Manual / Function Reference / File System Related Extensions / Filesystem
// URL: https://www.php.net/manual/en/book.filesystem.php
// ============================== DESCRIPTION
// FILESYSTEM
// FEATURES_HANDLING_FILE_UPLOADS
// APPENDICES_PHP_INI_DIRECTIVES_DESCRIPTION_OF_CORE_PHP_INI_DIRECTIVES
//
// FILESYSTEM - BEGIN
// Filesystem
//
// INTRODUCTION
// INSTALLING_CONFIGURING
// PREDEFINED_CONSTANTS
// FILESYSTEM_FUNCTIONS
//
// INTRODUCTION - BEGIN
// Introduction
//
// No external libraries are needed to build this extension, but if you want PHP to support LFS (large files) on Linux, then you need to have a recent glibc and you need compile PHP with the following compiler flags: -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64.
//
// LITERATURE_SOURCES
// * PHP_NET (2023-09-12)
// URL: https://www.php.net/manual/en/intro.filesystem.php
// INTRODUCTION - END
//
// INSTALLING_CONFIGURING - BEGIN
// Installing/Configuring
//
// REQUIREMENTS
// INSTALLATION
// RUNTIME_CONFIGURATION
// RESOURCE_TYPES
//
// REQUIREMENTS - BEGIN
// Requirements
//
// No external libraries are needed to build this extension.
//
// LITERATURE_SOURCES
// * PHP_NET (2023-09-12)
// URL: https://www.php.net/manual/en/filesystem.requirements.php
// REQUIREMENTS - END
//
// INSTALLATION - BEGIN
// Installation
//
// There is no installation needed to use these functions; they are part of the PHP core.
//
// LITERATURE_SOURCES
// * PHP_NET (2023-09-12)
// URL: https://www.php.net/manual/en/filesystem.installation.php
// INSTALLATION - END
//
// RUNTIME_CONFIGURATION - BEGIN
// Runtime Configuration
//
// The behaviour of these functions is affected by settings in php.ini.
//
// Filesystem and Streams Configuration Options
// Name | Default | Changeable | Changelog
// allow_url_fopen | "1" | PHP_INI_SYSTEM |
// allow_url_include | "0" | PHP_INI_SYSTEM | Deprecated as of PHP 7.4.0.
// user_agent | NULL | PHP_INI_ALL |
// default_socket_timeout | "60" | PHP_INI_ALL |
// from | "" | PHP_INI_ALL |
// auto_detect_line_endings | "0" | PHP_INI_ALL | Deprecated as of PHP 8.1.0.
// sys_temp_dir | "" | PHP_INI_SYSTEM |
//
// Here's a short explanation of the configuration directives.
//
// allow_url_fopen bool - This option enables the URL-aware fopen wrappers that enable accessing URL object like files. Default wrappers are provided for the access of remote files using the ftp or http protocol, some extensions like zlib may register additional wrappers.
// allow_url_include bool - This option allows the use of URL-aware fopen wrappers with the following functions: include, include_once, require, require_once.
// Note: This setting requires allow_url_fopen to be on.
// user_agent string - Define the user agent for PHP to send.
// default_socket_timeout int - Default timeout (in seconds) for socket based streams. Specifying a negative value means an infinite timeout.
// from string - The email address to be used on unauthenticated FTP connections and as the value of From header for HTTP connections, when using the ftp and http wrappers, respectively.
// auto_detect_line_endings bool - When turned on, PHP will examine the data read by fgets() and file() to see if it is using Unix, MS-Dos or Macintosh line-ending conventions.
// This enables PHP to interoperate with Macintosh systems, but defaults to Off, as there is a very small performance penalty when detecting the EOL conventions for the first line, and also because people using carriage-returns as item separators under Unix systems would experience non-backwards-compatible behaviour.
// sys_temp_dir string -
//
// LITERATURE_SOURCES
// * PHP_NET (2023-09-12)
// URL: https://www.php.net/manual/en/filesystem.configuration.php
// RUNTIME_CONFIGURATION - END
//
// RESOURCE_TYPES - BEGIN
// Resource Types
//
// The file system uses streams as their resource type. Streams are documented in its own reference chapter, Streams.
//
// LITERATURE_SOURCES
// * PHP_NET (2023-09-12)
// URL: https://www.php.net/manual/en/filesystem.resources.php
// RESOURCE_TYPES - END
//
// LITERATURE_SOURCES
// * PHP_NET (2023-09-12)
// URL: https://www.php.net/manual/en/filesystem.setup.php
// INSTALLING_CONFIGURING - END
//
// PREDEFINED_CONSTANTS - BEGIN
// Predefined Constants
//
// The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.
//
// SEEK_SET (int) -
// SEEK_CUR (int) -
// SEEK_END (int) -
// LOCK_SH (int) -
// LOCK_EX (int) -
// LOCK_UN (int) -
// LOCK_NB (int) -
// GLOB_BRACE (int) -
// GLOB_ONLYDIR (int) -
// GLOB_MARK (int) -
// GLOB_NOSORT (int) -
// GLOB_NOCHECK (int) -
// GLOB_NOESCAPE (int) -
// GLOB_AVAILABLE_FLAGS (int) -
// PATHINFO_DIRNAME (int) -
// PATHINFO_BASENAME (int) -
// PATHINFO_EXTENSION (int) -
// PATHINFO_FILENAME (int) -
// FILE_USE_INCLUDE_PATH (int) - Search for filename in include_path.
// FILE_NO_DEFAULT_CONTEXT (int) -
// FILE_APPEND (int) - Append content to existing file.
// FILE_IGNORE_NEW_LINES (int) - Strip EOL characters.
// FILE_SKIP_EMPTY_LINES (int) - Skip empty lines.
// FILE_BINARY (int) - Binary mode.
// Note: This constant has no effect, and is only available for forward compatibility.
// FILE_TEXT (int) - Text mode.
// Note: This constant has no effect, and is only available for forward compatibility.
// INI_SCANNER_NORMAL (int) - Normal INI scanner mode.
// INI_SCANNER_RAW (int) - Raw INI scanner mode.
// INI_SCANNER_TYPED (int) - Typed INI scanner mode.
// FNM_NOESCAPE (int) - Disable backslash escaping.
// FNM_PATHNAME (int) - Slash in string only matches slash in the given pattern.
// FNM_PERIOD (int) - Leading period in string must be exactly matched by period in the given pattern.
// FNM_CASEFOLD (int) - Caseless match. Part of the GNU extension.
//
// LITERATURE_SOURCES
// * PHP_NET (2023-09-12)
// URL: https://www.php.net/manual/en/filesystem.constants.php
// PREDEFINED_CONSTANTS - END
//
// FILESYSTEM_FUNCTIONS - BEGIN
// Filesystem Functions
//
// See Also
// For related functions, see also the Directory and Program Execution sections.
// For a list and explanation of the various URL wrappers that can be used as remote files, see also Supported Protocols and Wrappers.
//
// Table of Contents
// * basename - Returns trailing name component of path
// * chgrp - Changes file group
// * chmod - Changes file mode
// * chown - Changes file owner
// * clearstatcache - Clears file status cache
// * copy - Copies file
// * delete - See unlink or unset
// * dirname - Returns a parent directory's path
// * disk_free_space - Returns available space on filesystem or disk partition
// * disk_total_space - Returns the total size of a filesystem or disk partition
// * diskfreespace - Alias of disk_free_space
// * fclose - Closes an open file pointer
// * fdatasync - Synchronizes data (but not meta-data) to the file
// * feof - Tests for end-of-file on a file pointer
// * fflush - Flushes the output to a file
// * fgetc - Gets character from file pointer
// * fgetcsv - Gets line from file pointer and parse for CSV fields
// * fgets - Gets line from file pointer
// * fgetss - Gets line from file pointer and strip HTML tags
// * file_exists - Checks whether a file or directory exists
// * file_get_contents - Reads entire file into a string
// * file_put_contents - Write data to a file
// * file - Reads entire file into an array
// * fileatime - Gets last access time of file
// * filectime - Gets inode change time of file
// * filegroup - Gets file group
// * fileinode - Gets file inode
// * filemtime - Gets file modification time
// * fileowner - Gets file owner
// * fileperms - Gets file permissions
// * filesize - Gets file size
// * filetype - Gets file type
// * flock - Portable advisory file locking
// * fnmatch - Match filename against a pattern
// * fopen - Opens file or URL
// * fpassthru - Output all remaining data on a file pointer
// * fputcsv - Format line as CSV and write to file pointer
// * fputs - Alias of fwrite
// * fread - Binary-safe file read
// * fscanf - Parses input from a file according to a format
// * fseek - Seeks on a file pointer
// * fstat - Gets information about a file using an open file pointer
// * fsync - Synchronizes changes to the file (including meta-data)
// * ftell - Returns the current position of the file read/write pointer
// * ftruncate - Truncates a file to a given length
// * fwrite - Binary-safe file write
// * glob - Find pathnames matching a pattern
// * is_dir - Tells whether the filename is a directory
// * is_executable - Tells whether the filename is executable
// * is_file - Tells whether the filename is a regular file
// * is_link - Tells whether the filename is a symbolic link
// * is_readable - Tells whether a file exists and is readable
// * is_uploaded_file - Tells whether the file was uploaded via HTTP POST
// * is_writable - Tells whether the filename is writable
// * is_writeable - Alias of is_writable
// * lchgrp - Changes group ownership of symlink
// * lchown - Changes user ownership of symlink
// * link - Create a hard link
// * linkinfo - Gets information about a link
// * lstat - Gives information about a file or symbolic link
// * mkdir - Makes directory
// * move_uploaded_file - Moves an uploaded file to a new location
// * parse_ini_file - Parse a configuration file
// * parse_ini_string - Parse a configuration string
// * pathinfo - Returns information about a file path
// * pclose - Closes process file pointer
// * popen - Opens process file pointer
// * readfile - Outputs a file
// * readlink - Returns the target of a symbolic link
// * realpath_cache_get - Get realpath cache entries
// * realpath_cache_size - Get realpath cache size
// * realpath - Returns canonicalized absolute pathname
// * rename - Renames a file or directory
// * rewind - Rewind the position of a file pointer
// * rmdir - Removes directory
// * set_file_buffer - Alias of stream_set_write_buffer
// * stat - Gives information about a file
// * symlink - Creates a symbolic link
// * tempnam - Create file with unique file name
// * tmpfile - Creates a temporary file
// * touch - Sets access and modification time of file
// * umask - Changes the current umask
// * unlink - Deletes a file
//
// LITERATURE_SOURCES
// * PHP_NET (2023-09-12)
// URL: https://www.php.net/manual/en/ref.filesystem.php
// FILESYSTEM_FUNCTIONS - END
//
// LITERATURE_SOURCES
// * PHP_NET (2023-09-12)
// URL: https://www.php.net/manual/en/book.filesystem.php
// FILESYSTEM - END
//
// FEATURES_HANDLING_FILE_UPLOADS - BEGIN
// Handling file uploads (PHP Manual / Features / Handling file uploads)
//
// POST_METHOD_UPLOADS
// ERROR_MESSAGES_EXPLAINED
// COMMON_PITFALLS
// UPLOADING_MULTIPLE_FILES
// PUT_METHOD_SUPPORT
//
// Table of Contents
// * POST method uploads
// * Error Messages Explained
// * Common Pitfalls
// * Uploading multiple files
// * PUT method support
//
// POST_METHOD_UPLOADS - BEGIN
// POST method uploads
//
// This feature lets people upload both text and binary files. With PHP's authentication and file manipulation functions, you have full control over who is allowed to upload and what is to be done with the file once it has been uploaded.
// PHP is capable of receiving file uploads from any RFC-1867 compliant browser.
// Note: Related Configurations Note
// See also the file_uploads, upload_max_filesize, upload_tmp_dir, post_max_size and max_input_time directives in php.ini
// PHP also supports PUT-method file uploads as used by Netscape Composer and W3C's Amaya clients. See the PUT Method Support for more details.
// [example]
// Example #1 File Upload Form
// A file upload screen can be built by creating a special form which looks something like this:
// [code]
//
//
// [/code]
// The __URL__ in the above example should be replaced, and point to a PHP file.
// The MAX_FILE_SIZE hidden field (measured in bytes) must precede the file input field, and its value is the maximum filesize accepted by PHP. This form element should always be used as it saves users the trouble of waiting for a big file being transferred only to find that it was too large and the transfer failed. Keep in mind: fooling this setting on the browser side is quite easy, so never rely on files with a greater size being blocked by this feature. It is merely a convenience feature for users on the client side of the application. The PHP settings (on the server side) for maximum-size, however, cannot be fooled.
// Note: Be sure your file upload form has attribute enctype="multipart/form-data" otherwise the file upload will not work.
// [/example]
// The global $_FILES will contain all the uploaded file information. Its contents from the example form is as follows. Note that this assumes the use of the file upload name userfile, as used in the example script above. This can be any name.
// $_FILES['userfile']['name'] - The original name of the file on the client machine.
// $_FILES['userfile']['type'] - The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted.
// $_FILES['userfile']['size'] - The size, in bytes, of the uploaded file.
// $_FILES['userfile']['tmp_name'] - The temporary filename of the file in which the uploaded file was stored on the server.
// $_FILES['userfile']['error'] - The error code associated with this file upload.
// $_FILES['userfile']['full_path'] - The full path as submitted by the browser. This value does not always contain a real directory structure, and cannot be trusted. Available as of PHP 8.1.0.
// Files will, by default be stored in the server's default temporary directory, unless another location has been given with the upload_tmp_dir directive in php.ini. The server's default directory can be changed by setting the environment variable TMPDIR in the environment in which PHP runs. Setting it using putenv() from within a PHP script will not work. This environment variable can also be used to make sure that other operations are working on uploaded files, as well.
// [example]
// Example #2 Validating file uploads
// See also the function entries for is_uploaded_file() and move_uploaded_file() for further information. The following example will process the file upload that came from a form.
// [php]
// $uploaddir = '/var/www/uploads/';
// $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
//
// echo '';
// if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
// echo "File is valid, and was successfully uploaded.\n";
// } else {
// echo "Possible file upload attack!\n";
// }
//
// echo 'Here is some more debugging info:';
// print_r($_FILES);
//
// print "
";
//
// [/php]
// The PHP script which receives the uploaded file should implement whatever logic is necessary for determining what should be done with the uploaded file. You can, for example, use the $_FILES['userfile']['size'] variable to throw away any files that are either too small or too big. You could use the $_FILES['userfile']['type'] variable to throw away any files that didn't match a certain type criteria, but use this only as first of a series of checks, because this value is completely under the control of the client and not checked on the PHP side. Also, you could use $_FILES['userfile']['error'] and plan your logic according to the error codes. Whatever the logic, you should either delete the file from the temporary directory or move it elsewhere.
// If no file is selected for upload in your form, PHP will return $_FILES['userfile']['size'] as 0, and $_FILES['userfile']['tmp_name'] as none.
// The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.
// [/example]
// [example]
// Example #3 Uploading array of files
// PHP supports HTML array feature even with files.
// [code]
//
// [/code]
// [php]
// foreach ($_FILES["pictures"]["error"] as $key => $error) {
// if ($error == UPLOAD_ERR_OK) {
// $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
// // basename() may prevent filesystem traversal attacks;
// // further validation/sanitation of the filename may be appropriate
// $name = basename($_FILES["pictures"]["name"][$key]);
// move_uploaded_file($tmp_name, "data/$name");
// }
// }
// [/php]
// [/example]
// File upload progress bar can be implemented using Session Upload Progress.
//
// LITERATURE_SOURCES
// * PHP_NET (2023-12-31)
// URL: https://www.php.net/manual/en/features.file-upload.post-method.php
// POST_METHOD_UPLOADS - END
// ERROR_MESSAGES_EXPLAINED - BEGIN
// Error Messages Explained
//
// PHP returns an appropriate error code along with the file array. The error code can be found in the error segment of the file array that is created during the file upload by PHP. In other words, the error might be found in $_FILES['userfile']['error'].
// UPLOAD_ERR_OK - Value: 0; There is no error, the file uploaded with success.
// UPLOAD_ERR_INI_SIZE - Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
// UPLOAD_ERR_FORM_SIZE - Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
// UPLOAD_ERR_PARTIAL - Value: 3; The uploaded file was only partially uploaded.
// UPLOAD_ERR_NO_FILE - Value: 4; No file was uploaded.
// UPLOAD_ERR_NO_TMP_DIR - Value: 6; Missing a temporary folder.
// UPLOAD_ERR_CANT_WRITE - Value: 7; Failed to write file to disk.
// UPLOAD_ERR_EXTENSION - Value: 8; A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help.
//
// LITERATURE_SOURCES
// * PHP_NET (2023-07-26)
// URL: https://www.php.net/manual/en/features.file-upload.errors.php
// ERROR_MESSAGES_EXPLAINED - END
// COMMON_PITFALLS - BEGIN
// Common Pitfalls
//
// The MAX_FILE_SIZE item cannot specify a file size greater than the file size that has been set in the upload_max_filesize in the php.ini file. The default is 2 megabytes.
// If a memory limit is enabled, a larger memory_limit may be needed. Make sure you set memory_limit large enough.
// If max_execution_time is set too small, script execution may be exceeded by the value. Make sure you set max_execution_time large enough.
// Note: max_execution_time only affects the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), the sleep() function, database queries, time taken by the file upload process, etc. is not included when determining the maximum time that the script has been running.
// Warning: max_input_time sets the maximum time, in seconds, the script is allowed to receive input; this includes file uploads. For large or multiple files, or users on slower connections, the default of 60 seconds may be exceeded.
// If post_max_size is set too small, large files cannot be uploaded. Make sure you set post_max_size large enough.
// The max_file_uploads configuration setting controls the maximum number of files that can uploaded in one request. If more files are uploaded than the limit, then $_FILES will stop processing files once the limit is reached. For example, if max_file_uploads is set to 10, then $_FILES will never contain more than 10 items.
// Not validating which file you operate on may mean that users can access sensitive information in other directories.
// Due to the large amount of directory listing styles we cannot guarantee that files with exotic names (like containing spaces) are handled properly.
// A developer may not mix normal input fields and file upload fields in the same form variable (by using an input name like foo[]).
//
// LITERATURE_SOURCES
// * PHP_NET (2023-07-26)
// URL: https://www.php.net/manual/en/features.file-upload.common-pitfalls.php
// COMMON_PITFALLS - END
// UPLOADING_MULTIPLE_FILES - BEGIN
// Uploading multiple files
//
// Multiple files can be uploaded using different name for input.
// It is also possible to upload multiple files simultaneously and have the information organized automatically in arrays for you. To do so, you need to use the same array submission syntax in the HTML form as you do with multiple selects and checkboxes:
// [example]
// Example #1 Uploading multiple files
// [code]
//
// [/code]
// When the above form is submitted, the arrays $_FILES['userfile'], $_FILES['userfile']['name'], and $_FILES['userfile']['size'] will be initialized.
// For instance, assume that the filenames /home/test/review.html and /home/test/xwp.out are submitted. In this case, $_FILES['userfile']['name'][0] would contain the value review.html, and $_FILES['userfile']['name'][1] would contain the value xwp.out. Similarly, $_FILES['userfile']['size'][0] would contain review.html's file size, and so forth.
// $_FILES['userfile']['name'][0], $_FILES['userfile']['tmp_name'][0], $_FILES['userfile']['size'][0], and $_FILES['userfile']['type'][0] are also set.
// Warning: The max_file_uploads configuration setting acts as a limit on the number of files that can be uploaded in one request. You will need to ensure that your form does not try to upload more files in one request than this limit.
// [/example]
// [example]
// Example #2 Uploading an entire directory
// In HTML file upload fields, it is possible to upload an entire directory with the webkitdirectory attribute. This feature is supported in most modern browsers.
// With the full_path information, it is possible to store the relative paths, or reconstruct the same directory in the server.
// [code]
//
// [/code]
// Warning: The webkitdirectory attribute is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
// PHP only parses the relative path information submitted by the browser/user-agent, and passes that information to the $_FILES array. There is no guarantee that the values in the full_path array contains a real directory structure, and the PHP application must not trust this information.
// [/example]
//
// LITERATURE_SOURCES
// * PHP_NET (2023-12-31)
// URL: https://www.php.net/manual/en/features.file-upload.multiple.php
// UPLOADING_MULTIPLE_FILES - END
// PUT_METHOD_SUPPORT - BEGIN
// PUT method support
//
// PHP provides support for the HTTP PUT method used by some clients to store files on a server. PUT requests are much simpler than a file upload using POST requests and they look something like this:
// [code]
// PUT /path/filename.html HTTP/1.1
// [/code]
// This would normally mean that the remote client would like to save the content that follows as: /path/filename.html in your web tree. It is obviously not a good idea for Apache or PHP to automatically let everybody overwrite any files in your web tree. So, to handle such a request you have to first tell your web server that you want a certain PHP script to handle the request. In Apache you do this with the Script directive. It can be placed almost anywhere in your Apache configuration file. A common place is inside a block or perhaps inside a block. A line like this would do the trick:
// [code]
// Script PUT /put.php
// [/code]
// This tells Apache to send all PUT requests for URIs that match the context in which you put this line to the put.php script. This assumes, of course, that you have PHP enabled for the .php extension and PHP is active. The destination resource for all PUT requests to this script has to be the script itself, not a filename the uploaded file should have.
// With PHP you would then do something like the following in your put.php. This would copy the contents of the uploaded file to the file myputfile.ext on the server. You would probably want to perform some checks and/or authenticate the user before performing this file copy.
// [example]
// Example #1 Saving HTTP PUT files
// [php]
// // PUT data comes in on the stdin stream
// $putdata = fopen("php://input", "r");
//
// // Open a file for writing
// $fp = fopen("myputfile.ext", "w");
//
// // Read the data 1 KB at a time
// // and write to the file
// while ($data = fread($putdata, 1024))
// fwrite($fp, $data);
//
// // Close the streams
// fclose($fp);
// fclose($putdata);
// [/php]
// [/example]
//
// LITERATURE_SOURCES
// * PHP_NET (2023-07-26)
// URL: https://www.php.net/manual/en/features.file-upload.put-method.php
// PUT_METHOD_SUPPORT - END
//
// LITERATURE_SOURCES
// * PHP_NET (2023-07-26)
// URL: https://www.php.net/manual/en/features.file-upload.php
// FEATURES_HANDLING_FILE_UPLOADS - END
//
// APPENDICES_PHP_INI_DIRECTIVES_DESCRIPTION_OF_CORE_PHP_INI_DIRECTIVES - BEGIN
// Description of core php.ini directives (PHP Manual / Appendices / php.ini directives / Description of core php.ini directives)
//
// realpath_cache_size int - Determines the size of the realpath cache to be used by PHP. This value should be increased on systems where PHP opens many files, to reflect the quantity of the file operations performed.
// The size represents the total number of bytes in the path strings stored, plus the size of the data associated with the cache entry. This means that in order to store longer paths in the cache, the cache size must be larger. This value does not directly control the number of distinct paths that can be cached.
// The size required for the cache entry data is system dependent.
//
// LITERATURE_SOURCES
// * PHP_NET (2023-09-14)
// URL: https://www.php.net/manual/en/ini.core.php#ini.realpath-cache-size
// APPENDICES_PHP_INI_DIRECTIVES_DESCRIPTION_OF_CORE_PHP_INI_DIRECTIVES - END
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_FILES_VARIABLE
// ============================== PUBLIC
// ============================== ABOUT
// HTTP File Upload variables.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING VARIABLES (1)
// $_FILES - PHP_4 >= PHP_4_1_0, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_files_variable()
{
$return_files = null;
// ========== $_FILES - BEGIN
// ===== ABOUT
// HTTP File Upload variables
// ===== DESCRIPTION
// An associative array of items uploaded to the current script via the HTTP POST method. The structure of this array is outlined in the POST method uploads section.
// ===== SUPPORTED
// PHP_4 >= PHP_4_1_0, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// ===== CODE
$return_files = $_FILES;
// Notes
// Note: This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. There is no need to do global $variable; to access it within functions or methods.
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-07-26)
// URL: https://www.php.net/manual/en/reserved.variables.files.php
// ========== $_FILES - END
// SYNTAX:
// array $_FILES
return $return_files; // array
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_FILES_VARIABLE
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_BASENAME
// ============================== PUBLIC
// ============================== ABOUT
// Returns trailing name component of path.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// basename() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_basename($path, $suffix = "")
{
$return_basename = null;
// ========== BASENAME - BEGIN
// ===== ABOUT
// Returns trailing name component of path
// ===== DESCRIPTION
// Given a string containing the path to a file or directory, this function will return the trailing name component.
// Note: basename() operates naively on the input string, and is not aware of the actual filesystem, or path components such as "..".
// Caution: basename() is locale aware, so for it to see the correct basename with multibyte character paths, the matching locale must be set using the setlocale() function. If path contains characters which are invalid for the current locale, the behavior of basename() is undefined.
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// basename(string $path, string $suffix = ""): string
// ===== CODE
$return_basename = basename(
$path, // string path - A path.
// On Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).
$suffix // string suffix - If the name component ends in suffix this will also be cut off.
); // Return Values
// Returns the base name of the given path.
//
// [examples]
// Examples
// [example]
// Example #1 basename() example
// [php]
// echo "1) ".basename("/etc/sudoers.d", ".d").PHP_EOL;
// echo "2) ".basename("/etc/sudoers.d").PHP_EOL;
// echo "3) ".basename("/etc/passwd").PHP_EOL;
// echo "4) ".basename("/etc/").PHP_EOL;
// echo "5) ".basename(".").PHP_EOL;
// echo "6) ".basename("/");
// [/php]
// The above example will output:
// [result]
// 1) sudoers
// 2) sudoers.d
// 3) passwd
// 4) etc
// 5) .
// 6)
// [/result]
// [/example]
// [/examples]
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.basename.php
// ========== BASENAME - END
// SYNTAX:
// string basename(string $path, string $suffix = "")
return $return_basename; // string
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_BASENAME
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_CHGRP
// ============================== PUBLIC
// ============================== ABOUT
// Changes file group.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// chgrp() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_chgrp($filename, $group)
{
$return_chgrp = false;
// ========== CHGRP - BEGIN
// ===== ABOUT
// Changes file group
// ===== DESCRIPTION
// 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.
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// chgrp(string $filename, string|int $group): bool
// ===== CODE
$return_chgrp = chgrp(
$filename, // string filename - Path to the file.
$group // string|int group - A group name or number.
); // Return Values
// Returns true on success or false on failure.
//
// Notes
// Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem.
// Note: On Windows, this function fails silently when applied on a regular file.
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-09-11)
// URL: https://www.php.net/manual/en/function.chgrp.php
// ========== CHGRP - END
// SYNTAX:
// bool chgrp(string $filename, string|int $group)
return $return_chgrp; // bool
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_CHGRP
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_CHMOD
// ============================== PUBLIC
// ============================== ABOUT
// Changes file mode.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// chmod() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_chmod($filename, $permissions)
{
$return_chmod = false;
// ========== CHMOD - BEGIN
// ===== ABOUT
// Changes file mode
// ===== DESCRIPTION
// Attempts to change the mode of the specified file to that given in permissions.
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// chmod(string $filename, int $permissions): bool
// ===== CODE
$return_chmod = chmod(
$filename, // string filename - Path to the file.
$permissions // int permissions - Note that permissions is not automatically assumed to be an octal value, so to ensure the expected operation, you need to prefix permissions with a zero (0). Strings such as "g+w" will not work properly.
// [php]
// chmod("/somedir/somefile", 755); // decimal; probably incorrect
// chmod("/somedir/somefile", "u+rwx,go+rx"); // string; incorrect
// chmod("/somedir/somefile", 0755); // octal; correct value of mode
// [/php]
// The permissions parameter consists of three octal number components specifying access restrictions for the owner, the user group in which the owner is in, and to everybody else in this order. One component can be computed by adding up the needed permissions for that target user base. Number 1 means that you grant execute rights, number 2 means that you make the file writeable, number 4 means that you make the file readable. Add up these numbers to specify needed rights. You can also read more about modes on Unix systems with 'man 1 chmod' and 'man 2 chmod'.
// [php]
// // Read and write for owner, nothing for everybody else
// chmod("/somedir/somefile", 0600);
//
// // Read and write for owner, read for everybody else
// chmod("/somedir/somefile", 0644);
//
// // Everything for owner, read and execute for others
// chmod("/somedir/somefile", 0755);
//
// // Everything for owner, read and execute for owner's group
// chmod("/somedir/somefile", 0750);
// [/php]
); // Return Values
// Returns true on success or false on failure.
//
// Errors/Exceptions
// Upon failure, an E_WARNING is emitted.
//
// Notes
// Note: The current user is the user under which PHP runs. It is probably not the same user you use for normal shell or FTP access. The mode can be changed only by user who owns the file on most systems.
// Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem.
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.chmod.php
// ========== CHMOD - END
// SYNTAX:
// bool chmod(string $filename, int $permissions)
return $return_chmod; // bool
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_CHMOD
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_CHOWN
// ============================== PUBLIC
// ============================== ABOUT
// Changes file owner.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// chown() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_chown($filename, $user)
{
$return_chown = false;
// ========== CHOWN - BEGIN
// ===== ABOUT
// Changes file owner
// ===== DESCRIPTION
// Attempts to change the owner of the file filename to user user. Only the superuser may change the owner of a file.
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// chown(string $filename, string|int $user): bool
// ===== CODE
$return_chown = chown(
$filename, // string filename - Path to the file.
$user // string|int user - A user name or number.
); // Return Values
// Returns true on success or false on failure.
//
// [examples]
// Examples
// [example]
// Example #1 Simple chown() usage
// [php]
//
// // File name and username to use
// $file_name= "foo.php";
// $path = "/home/sites/php.net/public_html/sandbox/" . $file_name ;
// $user_name = "root";
//
// // Set the user
// chown($path, $user_name);
//
// // Check the result
// $stat = stat($path);
// print_r(posix_getpwuid($stat['uid']));
//
// [/php]
// The above example will output something similar to:
// [result]
// Array
// (
// [name] => root
// [passwd] => x
// [uid] => 0
// [gid] => 0
// [gecos] => root
// [dir] => /root
// [shell] => /bin/bash
// )
// [/result]
// [/example]
// [/examples]
//
// Notes
// Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem.
// Note: On Windows, this function fails silently when applied on a regular file.
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.chown.php
// ========== CHOWN - END
// SYNTAX:
// bool chown(string $filename, string|int $user)
return $return_chown; // bool
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_CHOWN
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_CLEARSTATCACHE
// ============================== PUBLIC
// ============================== ABOUT
// Clears file status cache.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// clearstatcache() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_clearstatcache($clear_realpath_cache = false, $filename = "")
{
// ========== CLEARSTATCACHE - BEGIN
// ===== ABOUT
// Clears file status cache
// ===== DESCRIPTION
// 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. In these cases, you can use the clearstatcache() function to clear the information that PHP caches about a file.
// You should also note that PHP doesn't cache information about non-existent files. So, if you call file_exists() on a file that doesn't exist, it will return false until you create the file. If you create the file, it will return true even if you then delete the file. However unlink() clears the cache automatically.
// Note: This function caches information about specific filenames, so you only need to call clearstatcache() if you are performing multiple operations on the same filename and require the information about that particular file to not be cached.
// 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 fileperms().
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// clearstatcache(bool $clear_realpath_cache = false, string $filename = ""): void
// ===== CODE
clearstatcache(
$clear_realpath_cache, // bool clear_realpath_cache - Whether to also clear the realpath cache.
$filename // string filename - Clear the realpath cache for a specific filename only; only used if clear_realpath_cache is true.
); // Return Values
// No value is returned.
//
// [examples]
// Examples
// [example]
// Example #1 clearstatcache() example
// [php]
// $file = 'output_log.txt';
//
// function get_owner($file)
// {
// $stat = stat($file);
// $user = posix_getpwuid($stat['uid']);
// return $user['name'];
// }
//
// $format = "UID @ %s: %s\n";
//
// printf($format, date('r'), get_owner($file));
//
// chown($file, 'ross');
// printf($format, date('r'), get_owner($file));
//
// clearstatcache();
// printf($format, date('r'), get_owner($file));
// [/php]
// The above example will output something similar to:
// [result]
// UID @ Sun, 12 Oct 2008 20:48:28 +0100: root
// UID @ Sun, 12 Oct 2008 20:48:28 +0100: root
// UID @ Sun, 12 Oct 2008 20:48:28 +0100: ross
// [/result]
// [/example]
// [/examples]
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.clearstatcache.php
// ========== CLEARSTATCACHE - END
// SYNTAX:
// void clearstatcache(bool $clear_realpath_cache = false, string $filename = "")
// Return: void
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_CLEARSTATCACHE
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_COPY
// ============================== PUBLIC
// ============================== ABOUT
// Copies file.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// copy() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_copy($from, $to, $context = null)
{
$return_copy = false;
// ========== COPY - BEGIN
// ===== ABOUT
// Copies file
// ===== DESCRIPTION
// Makes a copy of the file from to to.
// If you wish to move a file, use the rename() function.
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// copy(string $from, string $to, ?resource $context = null): bool
// ===== CODE
$return_copy = copy(
$from, // string $from - Path to the source file.
$to, // string $to - The destination path. If to 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.
$context // resource $context - A valid context resource created with stream_context_create().
); // Return Values
// Returns true on success or false on failure.
//
// [examples]
// Examples
// [example]
// Example #1 copy() example
// [php]
// $file = 'example.txt';
// $newfile = 'example.txt.bak';
//
// if (!copy($file, $newfile)) {
// echo "failed to copy $file...\n";
// }
// [/php]
// [/example]
// [/examples]
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.copy.php
// ========== COPY - END
// SYNTAX:
// bool copy(string $from, string $to, resource $context = null)
return $return_copy; // bool
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_COPY
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_DELETE
// ============================== PUBLIC
// ============================== ABOUT
// Deletes a file.
//
// delete - See unlink() or unset().
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// unlink() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_delete($filename, $context = null)
{
$return_delete = false;
// ========== DELETE - BEGIN
// ===== ABOUT
// delete - See unlink() or unset()
// ===== DESCRIPTION
// There is no delete keyword or function in the PHP language. If you arrived at this page seeking to delete a file, try unlink(). To delete a variable from the local scope, check out unset().
// ===== SUPPORTED
// ===== SYNTAX
// ===== CODE
$return_delete = unlink(
$filename, // string $filename
$context // resource $context
); // Return
// bool
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.delete.php
// ========== DELETE - END
// ========== UNLINK - BEGIN
// ===== ABOUT
// Deletes a file
// ===== DESCRIPTION
// Deletes filename. Similar to the Unix C unlink() function. An E_WARNING level error will be generated on failure.
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// unlink(string $filename, ?resource $context = null): bool
// ===== CODE
// $return_unlink = unlink(
// $filename, // string filename - Path to the file.
// If the file is a symlink, the symlink will be deleted. On Windows, to delete a symlink to a directory, rmdir() has to be used instead.
// $context // resource context - A context stream resource.
// ); // Return Values
// Returns true on success or false on failure.
//
// Changelog
// Version - Description
// 7.3.0 - On Windows, it is now possible to unlink() files with handles in use, while formerly that would fail. However, it is still not possible to re-create the unlinked file, until all handles to it have been closed.
//
// [examples]
// Examples
// [example]
// Example #1 Basic unlink() usage
// [php]
// $fh = fopen('test.html', 'a');
// fwrite($fh, 'Hello world!
');
// fclose($fh);
//
// unlink('test.html');
// [/php]
// [/example]
// [/examples]
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.unlink.php
// ========== UNLINK - END
// SYNTAX:
// bool unlink(string $filename, resource $context = null)
// * There is no delete keyword or function in the PHP language - To delete a variable from the local scope, check out unset().
return $return_delete; // bool
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_DELETE
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_DIRNAME
// ============================== PUBLIC
// ============================== ABOUT
// Returns a parent directory's path.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// dirname() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_dirname($path, $levels = 1)
{
$return_dirname = null;
// ========== DIRNAME - BEGIN
// ===== ABOUT
// Returns a parent directory's path
// ===== DESCRIPTION
// Given a string containing the path of a file or directory, this function will return the parent directory's path that is levels up from the current directory.
// Note: dirname() operates naively on the input string, and is not aware of the actual filesystem, or path components such as "..".
// Caution:
// On Windows, dirname() assumes the currently set codepage, so for it to see the correct directory name with multibyte character paths, the matching codepage must be set. If path contains characters which are invalid for the current codepage, the behavior of dirname() is undefined.
// On other systems, dirname() assumes path to be encoded in an ASCII compatible encoding. Otherwise the behavior of the the function is undefined.
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// dirname(string $path, int $levels = 1): string
// ===== CODE
$return_dirname = dirname(
$path, // string path - A path.
// On Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).
$levels // int levels - The number of parent directories to go up.
// This must be an integer greater than 0.
); // Return Values
// Returns the path of a parent 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.
// Caution:
// Be careful when using this function in a loop that can reach the top-level directory as this can result in an infinite loop.
// [php]
// dirname('.'); // Will return '.'.
// dirname('/'); // Will return `\` on Windows and '/' on *nix systems.
// dirname('\\'); // Will return `\` on Windows and '.' on *nix systems.
// dirname('C:\\'); // Will return 'C:\' on Windows and '.' on *nix systems.
// [/php]
//
// Changelog
// Version - Description
// 7.0.0 - Added the optional levels parameter.
//
// [examples]
// Examples
// [example]
// Example #1 dirname() example
// [php]
// echo dirname("/etc/passwd") . PHP_EOL;
// echo dirname("/etc/") . PHP_EOL;
// echo dirname(".") . PHP_EOL;
// echo dirname("C:\\") . PHP_EOL;
// echo dirname("/usr/local/lib", 2);
// [/php]
// The above example will output something similar to:
// [result]
// /etc
// / (or \ on Windows)
// .
// C:\
// /usr
// [/result]
// [/example]
// [/examples]
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.dirname.php
// ========== DIRNAME - END
// SYNTAX:
// string dirname(string $path, int $levels = 1)
return $return_dirname; // string
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_DIRNAME
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_DISK_FREE_SPACE
// ============================== PUBLIC
// ============================== ABOUT
// Returns available space on filesystem or disk partition.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// disk_free_space() - PHP_4 >= PHP_4_1_0, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_disk_free_space($directory)
{
$return_disk_free_space = false;
// ========== DISK_FREE_SPACE - BEGIN
// ===== ABOUT
// Returns available space on filesystem or disk partition
// ===== DESCRIPTION
// Given a string containing a directory, this function will return the number of bytes available on the corresponding filesystem or disk partition.
// ===== SUPPORTED
// PHP_4 >= PHP_4_1_0, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// disk_free_space(string $directory): float|false
// ===== CODE
$return_disk_free_space = disk_free_space(
$directory // string directory - A directory of the filesystem or disk partition.
// Note: Given a file name instead of a directory, the behaviour of the function is unspecified and may differ between operating systems and PHP versions.
); // Return Values
// Returns the number of available bytes as a float or false on failure.
//
// [examples]
// Examples
// [example]
// Example #1 disk_free_space() example
// [php]
// // $df contains the number of bytes available on "/"
// $df = disk_free_space("/");
//
// // On Windows:
// $df_c = disk_free_space("C:");
// $df_d = disk_free_space("D:");
// [/php]
// [/example]
// [/examples]
//
// Notes
// Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem.
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.disk-free-space.php
// ========== DISK_FREE_SPACE - END
// SYNTAX:
// float|false disk_free_space(string $directory)
return $return_disk_free_space; // float|false
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_DISK_FREE_SPACE
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_DISK_TOTAL_SPACE
// ============================== PUBLIC
// ============================== ABOUT
// Returns the total size of a filesystem or disk partition.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// disk_total_space() - PHP_4 >= PHP_4_1_0, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_disk_total_space($directory)
{
$return_disk_total_space = false;
// ========== DISK_TOTAL_SPACE - BEGIN
// ===== ABOUT
// Returns the total size of a filesystem or disk partition
// ===== DESCRIPTION
// Given a string containing a directory, this function will return the total number of bytes on the corresponding filesystem or disk partition.
// ===== SUPPORTED
// PHP_4 >= PHP_4_1_0, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// disk_total_space(string $directory): float|false
// ===== CODE
$return_disk_total_space = disk_total_space(
$directory // string directory - A directory of the filesystem or disk partition.
); // Return Values
// Returns the total number of bytes as a float or false on failure.
//
// [examples]
// Examples
// [example]
// Example #1 disk_total_space() example
// [php]
// // $ds contains the total number of bytes available on "/"
// $ds = disk_total_space("/");
//
// // On Windows:
// $ds = disk_total_space("C:");
// $ds = disk_total_space("D:");
// [/php]
// [/example]
// [/examples]
//
// Notes
// Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem.
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.disk-total-space.php
// ========== DISK_TOTAL_SPACE - END
// SYNTAX:
// float|false disk_total_space(string $directory)
return $return_disk_total_space; // float|false
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_DISK_TOTAL_SPACE
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_DISKFREESPACE
// ============================== PUBLIC
// ============================== ABOUT
// Returns available space on filesystem or disk partition.
//
// diskfreespace - Alias of disk_free_space().
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// diskfreespace() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_diskfreespace($directory)
{
$return_diskfreespace = false;
// ========== DISKFREESPACE - BEGIN
// ===== ABOUT
// diskfreespace - Alias of disk_free_space()
// ===== DESCRIPTION
// This function is an alias of: disk_free_space().
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// ===== CODE
$return_diskfreespace = diskfreespace(
$directory // string $directory
); // Return
// float|false
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.diskfreespace.php
// ========== DISKFREESPACE - END
// ========== DISK_FREE_SPACE - BEGIN
// ===== ABOUT
// Returns available space on filesystem or disk partition
// ===== DESCRIPTION
// Given a string containing a directory, this function will return the number of bytes available on the corresponding filesystem or disk partition.
// ===== SUPPORTED
// PHP_4 >= PHP_4_1_0, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// disk_free_space(string $directory): float|false
// ===== CODE
// $return_disk_free_space = disk_free_space(
// $directory // string directory - A directory of the filesystem or disk partition.
// Note: Given a file name instead of a directory, the behaviour of the function is unspecified and may differ between operating systems and PHP versions.
// ); // Return Values
// Returns the number of available bytes as a float or false on failure.
//
// [examples]
// Examples
// [example]
// Example #1 disk_free_space() example
// [php]
// // $df contains the number of bytes available on "/"
// $df = disk_free_space("/");
//
// // On Windows:
// $df_c = disk_free_space("C:");
// $df_d = disk_free_space("D:");
// [/php]
// [/example]
// [/examples]
//
// Notes
// Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem.
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.disk-free-space.php
// ========== DISK_FREE_SPACE - END
// SYNTAX:
// float|false diskfreespace(string $directory)
return $return_diskfreespace; // float|false
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_DISKFREESPACE
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_FCLOSE
// ============================== PUBLIC
// ============================== ABOUT
// Closes an open file pointer.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// fclose() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_fclose($stream)
{
$return_fclose = false;
// ========== FCLOSE - BEGIN
// ===== ABOUT
// Closes an open file pointer
// ===== DESCRIPTION
// The file pointed to by stream is closed.
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// fclose(resource $stream): bool
// ===== CODE
$return_fclose = fclose(
$stream // resource stream - The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen().
); // Return Values
// Returns true on success or false on failure.
//
// [examples]
// Examples
// [example]
// Example #1 A simple fclose() example
// [php]
//
// $handle = fopen('somefile.txt', 'r');
//
// fclose($handle);
//
// [/php]
// [/example]
// [/examples]
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.fclose.php
// ========== FCLOSE - END
// SYNTAX:
// bool fclose(resource $stream)
return $return_fclose; // bool
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_FCLOSE
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_FDATASYNC
// ============================== OFFLINE
// ============================== ABOUT
// Synchronizes data (but not meta-data) to the file.
// ============================== SUPPORT
// PHP_8
// ============================== USING FUNCTIONS (1)
// fdatasync() - PHP_8 >= PHP_8_1_0
// ============================== CODE
/*
function php_filesystem_filesystem_fdatasync($stream)
{
$return_fdatasync = false;
// ========== FDATASYNC - BEGIN
// ===== ABOUT
// Synchronizes data (but not meta-data) to the file
// ===== DESCRIPTION
// This function synchronizes stream contents to storage media, just like fsync() does, but it does not synchronize file meta-data. Note that this function is only effectively different in POSIX systems. In Windows, this function is aliased to fsync().
// ===== SUPPORTED
// PHP_8 >= PHP_8_1_0
// ===== SYNTAX
// fdatasync(resource $stream): bool
// ===== CODE
$return_fdatasync = fdatasync(
$stream // resource stream - The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).
); // Return Values
// Returns true on success or false on failure.
//
// [examples]
// Examples
// [example]
// Example #1 fdatasync() example
// [php]
//
// $file = 'test.txt';
//
// $stream = fopen($file, 'w');
// fwrite($stream, 'test data');
// fwrite($stream, "\r\n");
// fwrite($stream, 'additional data');
//
// fdatasync($stream);
// fclose($stream);
// [/php]
// [/example]
// [/examples]
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.fdatasync.php
// ========== FDATASYNC - END
// SYNTAX:
// bool fdatasync(resource $stream)
return $return_fdatasync; // bool
}
*/
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_FDATASYNC
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_FEOF
// ============================== PUBLIC
// ============================== ABOUT
// Tests for end-of-file on a file pointer.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// feof() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_feof($stream)
{
$return_feof = false;
// ========== FEOF - BEGIN
// ===== ABOUT
// Tests for end-of-file on a file pointer
// ===== DESCRIPTION
// Tests for end-of-file on a file pointer.
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// feof(resource $stream): bool
// ===== CODE
$return_feof = feof(
$stream // resource stream - The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).
); // Return Values
// Returns true if the file pointer is at EOF or an error occurs (including socket timeout); otherwise returns false.
//
// Notes
// Warning: If a connection opened by fsockopen() wasn't closed by the server, feof() will hang. To workaround this, see below example:
// Example #1 Handling timeouts with feof()
// [php]
// function safe_feof($fp, &$start = NULL) {
// $start = microtime(true);
//
// return feof($fp);
// }
//
// // Assuming $fp is previously opened by fsockopen()
//
// $start = NULL;
// $timeout = ini_get('default_socket_timeout');
//
// while(!safe_feof($fp, $start) && (microtime(true) - $start) < $timeout)
// {
// // Handle
// }
// [/php]
// Warning: If the passed file pointer is not valid you may get an infinite loop, because feof() fails to return true.
// Example #2 feof() example with an invalid file pointer
// [php]
// // if file can not be read or doesn't exist fopen function returns FALSE
// $file = @fopen("no_such_file", "r");
//
// // FALSE from fopen will issue warning and result in infinite loop here
// while (!feof($file)) {
// }
//
// fclose($file);
// [/php]
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.feof.php
// ========== FEOF - END
// SYNTAX:
// bool feof(resource $stream)
return $return_feof; // bool
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_FEOF
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_FFLUSH
// ============================== PUBLIC
// ============================== ABOUT
// Flushes the output to a file.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// fflush() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_fflush($stream)
{
$return_fflush = false;
// ========== FFLUSH - BEGIN
// ===== ABOUT
// Flushes the output to a file
// ===== DESCRIPTION
// This function forces a write of all buffered output to the resource pointed to by the file stream.
// ===== SUPPORTED
// PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// fflush(resource $stream): bool
// ===== CODE
$return_fflush = fflush(
$stream // resource stream - The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).
); // Return Values
// Returns true on success or false on failure.
//
// [examples]
// Examples
// [example]
// Example #1 File write example using fflush()
// [php]
// $filename = 'bar.txt';
//
// $file = fopen($filename, 'r+');
// rewind($file);
// fwrite($file, 'Foo');
// fflush($file);
// ftruncate($file, ftell($file));
// fclose($file);
// [/php]
// [/example]
// [/examples]
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.fflush.php
// ========== FFLUSH - END
// SYNTAX:
// bool fflush(resource $stream)
return $return_fflush; // bool
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_FFLUSH
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_FGETC
// ============================== PUBLIC
// ============================== ABOUT
// Gets character from file pointer.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// fgetc() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_fgetc($stream)
{
$return_fgetc = false;
// ========== FGETC - BEGIN
// ===== ABOUT
// Gets character from file pointer
// ===== DESCRIPTION
// Gets a character from the given file pointer.
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// fgetc(resource $stream): string|false
// ===== CODE
$return_fgetc = fgetc(
$stream // resource stream - The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).
); // Return Values
// Returns a string containing a single character read from the file pointed to by stream. Returns false on EOF.
// Warning: This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.
//
// [examples]
// Examples
// [example]
// Example #1 A fgetc() example
// [php]
// $fp = fopen('somefile.txt', 'r');
// if (!$fp) {
// echo 'Could not open file somefile.txt';
// }
// while (false !== ($char = fgetc($fp))) {
// echo "$char\n";
// }
// [/php]
// [/example]
// [/examples]
//
// Notes
// Note: This function is binary-safe.
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.fgetc.php
// ========== FGETC - END
// SYNTAX:
// string|false fgetc(resource $stream)
return $return_fgetc; // string|false
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_FGETC
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_FGETCSV
// ============================== PUBLIC
// ============================== ABOUT
// Gets line from file pointer and parse for CSV fields.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// fgetcsv() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_fgetcsv($stream, $length = null, $separator = ",", $enclosure = "\"", $escape = "\\")
{
$return_fgetcsv = false;
// ========== FGETCSV - BEGIN
// ===== ABOUT
// Gets line from file pointer and parse for CSV fields
// ===== DESCRIPTION
// Similar to fgets() except that fgetcsv() parses the line it reads for fields in CSV format and returns an array containing the fields read.
// Note: The locale settings are taken into account by this function. If LC_CTYPE is e.g. en_US.UTF-8, files in one-byte encodings may be read wrongly by this function.
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// fgetcsv(
// resource $stream,
// ?int $length = null,
// string $separator = ",",
// string $enclosure = "\"",
// string $escape = "\\"
// ): array|false
// ===== CODE
$return_fgetcsv = fgetcsv(
$stream, // resource stream - A valid file pointer to a file successfully opened by fopen(), popen(), or fsockopen().
$length, // int length - Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters). Otherwise the line is split in chunks of length characters, unless the split would occur inside an enclosure.
// Omitting this parameter (or setting it to 0, or null in PHP 8.0.0 or later) the maximum line length is not limited, which is slightly slower.
$separator, // string separator - The optional separator parameter sets the field separator (one single-byte character only).
$enclosure, // string enclosure - The optional enclosure parameter sets the field enclosure character (one single-byte character only).
$escape // string escape - The optional escape parameter sets the escape character (at most one single-byte character). An empty string ("") disables the proprietary escape mechanism.
// Note: Usually an enclosure character is escaped inside a field by doubling it; however, the escape character can be used as an alternative. So for the default parameter values "" and \" have the same meaning. Other than allowing to escape the enclosure character the escape character has no special meaning; it isn't even meant to escape itself.
); // Return Values
// Returns an indexed array containing the fields read on success, or false on failure.
// 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.
//
// Changelog
// Version - Description
// 8.0.0 - length is now nullable.
// 7.4.0 - The escape parameter now also accepts an empty string to disable the proprietary escape mechanism.
//
// [examples]
// Examples
// [example]
// Example #1 Read and print the entire contents of a CSV file
// [php]
// $row = 1;
// if (($handle = fopen("test.csv", "r")) !== FALSE) {
// while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
// $num = count($data);
// echo " $num fields in line $row:
\n";
// $row++;
// for ($c=0; $c < $num; $c++) {
// echo $data[$c] . "
\n";
// }
// }
// fclose($handle);
// }
// [/php]
// [/example]
// [/examples]
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-31)
// URL: https://www.php.net/manual/en/function.fgetcsv.php
// ========== FGETCSV - END
// SYNTAX:
// array|false fgetcsv(resource $stream, int $length = null, string $separator = ",", string $enclosure = "\"", string $escape = "\\")
return $return_fgetcsv; // array|false
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_FGETCSV
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_FGETS
// ============================== PUBLIC
// ============================== ABOUT
// Gets line from file pointer.
// ============================== SUPPORT
// PHP_4 - PHP_8
// ============================== USING FUNCTIONS (1)
// fgets() - PHP_4, PHP_5, PHP_7, PHP_8
// ============================== CODE
function php_filesystem_filesystem_fgets($stream, $length = null)
{
$return_fgets = false;
// ========== FGETS - BEGIN
// ===== ABOUT
// Gets line from file pointer
// ===== DESCRIPTION
// Gets a line from file pointer.
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7, PHP_8
// ===== SYNTAX
// fgets(resource $stream, ?int $length = null): string|false
// ===== CODE
$return_fgets = fgets(
$stream, // resource stream - 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 // int length - Reading ends when length - 1 bytes have been read, or a newline (which is included in the return value), or an EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line.
); // Return Values
// Returns a string of up to length - 1 bytes read from the file pointed to by stream. If there is no more data to read in the file pointer, then false is returned.
// If an error occurs, false is returned.
//
// [examples]
// Examples
// [example]
// Example #1 Reading a file line by line
// [php]
// $fp = @fopen("/tmp/inputfile.txt", "r");
// if ($fp) {
// while (($buffer = fgets($fp, 4096)) !== false) {
// echo $buffer;
// }
// if (!feof($fp)) {
// echo "Error: unexpected fgets() fail\n";
// }
// fclose($fp);
// }
// [/php]
// [/example]
// [/examples]
//
// Notes
// 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.
// Note: People used to the 'C' semantics of fgets() should note the difference in how EOF is returned.
// ===== LITERATURE_SOURCES
// * PHP_NET (2023-12-30)
// URL: https://www.php.net/manual/en/function.fgets.php
// ========== FGETS - END
// SYNTAX:
// string|false fgets(resource $stream, int $length = null)
return $return_fgets; // string|false
}
// ============================== END
// PHP_FILESYSTEM_FILESYSTEM_FGETS
// ==============================
// ============================== BEGIN
// PHP_FILESYSTEM_FILESYSTEM_FGETSS
// ============================== OFFLINE
// ============================== ABOUT
// Gets line from file pointer and strip HTML tags.
//
// Warning: This function has been DEPRECATED as of PHP 7.3.0, and REMOVED as of PHP 8.0.0. Relying on this function is highly discouraged.
// ============================== SUPPORT
// PHP_4 - PHP_7
// ============================== USING FUNCTIONS (1)
// fgetss() - PHP_4, PHP_5, PHP_7
// ============================== CODE
/*
function php_filesystem_filesystem_fgetss($handle, $length, $allowable_tags)
{
$return_fgetss = null;
// ========== FGETSS - BEGIN
// ===== ABOUT
// Gets line from file pointer and strip HTML tags
// Warning: This function has been DEPRECATED as of PHP 7.3.0, and REMOVED as of PHP 8.0.0. Relying on this function is highly discouraged.
// ===== DESCRIPTION
// Identical to fgets(), except that fgetss() attempts to strip any NUL bytes, HTML and PHP tags from the text it reads. The function retains the parsing state from call to call, and as such is not equivalent to calling strip_tags() on the return value of fgets().
// ===== SUPPORTED
// PHP_4, PHP_5, PHP_7
// ===== SYNTAX
// fgetss(resource $handle, int $length = ?, string $allowable_tags = ?): string
// ===== CODE
$return_fgetss = fgetss(
$handle, // resource 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, // int length - Length of the data to be retrieved.
$allowable_tags // string allowable_tags - You can use the optional third parameter to specify tags which should not be stripped. See strip_tags() for details regarding allowable_tags.
); // Return Values
// 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.
//
// [examples]
// Examples
// [example]
// Example #1 Reading a PHP file line-by-line
// [php]
// $str = <<
// Welcome! Today is the of = date('F'); ?>.
//