- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
Various URL-style protocols can be used with filesystem functions with the help of corresponding built-in wrappers avalable in PHP. The stream_wrapper_register() function is also there to define custom wrapper.
Default wrapper in PHP is file:// and it represents local filesystem. If no other protocol is explicitly used, PHP parser treats it as filesystem wrapper. The filename argument to be given to filesystem functions fopen(), file_get_contents() etc uses file:// protocol by default.
When file name doesn't begin with forward or backward slash, or drive letter in Windows, its path is taken as relative to current directory. However, in fopen() and file_get_contents() functions, file name may be searched in locations mentioned in include_path directive.
The file:// wrapper supports simultaneous read/write operations, creating and removing directory, and renaming a file. Also, file access is not restricted by allow_url_fopen directive in php.ini configuration settings.
Representation of file name in different possible ways is as follows −
//relative path (assuming current working directory is c:\xampp\php, file is opened in tst subdirectory)
//current path. File will be opened in c:\xampp\php\test directory assuming it as current directory
//using file://protocolfor absolute path
//using file://protocol for file in document root
- Related Articles
- file() function in PHP
- Upload file with php to another php server
- How to force file download with PHP?
- How to echo XML file in PHP
- How to import csv file in PHP?
- Read last line from file in PHP
- PHP Defining Multiple Namespaces in same file
- How to display errors in PHP file?
- Download file through an AJAX call in PHP
- Reading/Writing a MS Word file in PHP
- How to call Python file from within PHP?
- How to parse a CSV file using PHP
- How to convert XML file into array in PHP?
- How can I extract or uncompress gzip file using php?
- How to get file name from a path in PHP?