Home > Backend Development > PHP Tutorial > php 怎么导入根目录下的文件?

php 怎么导入根目录下的文件?

WBOY
Release: 2016-06-06 20:06:54
Original
2319 people have browsed it

就是类似 HTML 的

<code>@import url( "/mystyle.css" );
//导入 服务根目录 下的 mystyle.css 文件?</code>
Copy after login
Copy after login
<code>比如服务器在 C:\AppServ\www\ ,要到入  C:\AppServ\www\1.php

只能用 include( "..\(省略N个)..\1.php" ); 一直找到根目录,


不能用一个 斜杠,或者 符号代替吗?
</code>
Copy after login
Copy after login

回复内容:

就是类似 HTML 的

<code>@import url( "/mystyle.css" );
//导入 服务根目录 下的 mystyle.css 文件?</code>
Copy after login
Copy after login
<code>比如服务器在 C:\AppServ\www\ ,要到入  C:\AppServ\www\1.php

只能用 include( "..\(省略N个)..\1.php" ); 一直找到根目录,


不能用一个 斜杠,或者 符号代替吗?
</code>
Copy after login
Copy after login

<code>$PATH = dirname(realpath(__file__));
$PATH = preg_replace("/\\/", '/', $PATH);
$PATH = substr($PATH, 0, strpos($PATH, 'www') ) . 'www';</code>
Copy after login

这个还没有测试,不过楼主可以试试

用dirname(__FILE__)呢?

echo $_SERVER['DOCUMENT_ROOT']

Related labels:
php
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template