How to convert path to actual path (absolute address) in php

青灯夜游
Release: 2023-03-16 11:00:02
Original
2633 people have browsed it

In PHP, you can use the realpath() function to convert the path into an actual path, with the syntax "realpath(path)". The realpath() function can accept the relative path of a file as the value of the parameter "path", and then return the absolute path (information about the location of the actual file), which contains the file name.

How to convert path to actual path (absolute address) in php

The operating environment of this tutorial: windows7 system, PHP version 8.1, DELL G3 computer

php converts the path to the actual path (Absolute address) method

We know the relative path to execute the PHP script, assign it to$filename, and then use realpath($filename) to get the absolute path of the file (including the file name) and learn the location information of$filename.

Copy after login

The output result is:

How to convert path to actual path (absolute address) in php

It can be seen that of course the file$filenameis in the sub-section of the wamp directory on the c drive In the directory www.

The absolute path returned by the realpath() function contains the file name. If you don’t want it, you can use the dirname() function to remove it

Copy after login

How to convert path to actual path (absolute address) in php

Recommended learning: "PHP video tutorial

The above is the detailed content of How to convert path to actual path (absolute address) in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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!