PHP file://

PHPz
Release: 2023-08-20 18:14:01
forward
1292 people have browsed it

PHP file://

Introduction

In PHP, various URL style protocols can be used in conjunction with file system functions, with the help of corresponding built-in wrappers. Custom wrappers can also be defined using the stream_wrapper_register() function.

The default wrapper in PHP is file://, which represents the local file system. If no other protocol is explicitly used, the PHP parser will treat it as a filesystem wrapper. The file name parameters passed to the file system functions fopen(), file_get_contents(), etc. use the file:// protocol by default.

When a filename does not begin with a forward slash, a backslash, or a drive letter in Windows, its path is considered relative to the current directory. However, in the fopen() and file_get_contents() functions, the file name may be searched in the location specified in the include_path directive.

The file:// wrapper supports simultaneous read and write operations, creating and deleting directories, and renaming files. Additionally, file access is not restricted by the allow_url_fopen directive in the php.ini configuration settings.

Example

The file names represented in different possible ways are as follows:

//Absolute path

$file=fopen("C:/xampp/php/test/test.txt","w");
Copy after login

//Relative path (assuming the current working directory is c:\xampp\php, the file is opened in the tst subdirectory)

$file=fopen("test/test.txt","w");
Copy after login

//Current path. Assuming the file will be opened in the c:\xampp\php\test directory, treat it as the current directory

$file=fopen("test.txt","w");
Copy after login

//Use the file:// protocol to represent absolute paths

$file=fopen("file:///c:/xampp/php/test/test.txt","w");
Copy after login

//Use file:// protocolAccess files in the document root directory

$file=fopen("file://localhost/test/test.txt","w");
Copy after login

The above is the detailed content of PHP file://. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template