PHP file://

PHPz
Release: 2023-08-20 18:14:01
forward
1216 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 thestream_wrapper_register()function.

The default wrapper in PHP isfile://, 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 functionsfopen(),file_get_contents(), etc. use thefile://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 theinclude_pathdirective.

The file:// wrapper supports simultaneous read and write operations, creating and deleting directories, and renaming files. Additionally, file access is not restricted by theallow_url_fopendirective 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:// protocolto 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!