在PHP中使用required / included文件作为基本目录 [英] Use the required / included file as base directory in PHP

查看:142
本文介绍了在PHP中使用required / included文件作为基本目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用index.php来包含另一个文件,其结构如下:

I am currently using an index.php to include another file , it structure like:

root / index.php
     / new/ index.php

我使用

<?php
require_once("new/index.php");
?>

问题是,其中的所有路径都是错误的。由于所有路径都基于new / index.php,因此当我包含它时,所有路径都会根据index.php进行更改。有没有办法让局外人访问index.php,但同时我的实际代码存储在new /文件夹中?谢谢

the problem is , all paths in it are wrong. As all paths are based on new/index.php , when i include it, all paths changes to based on index.php. Are there any way to let the outsider visit index.php but at the same time my actual code is stored in new/ folder? Thanks

推荐答案

你在说什么

<?php echo '<img src="my_image.jpg">; ?>

如果是这样,请使用斜杠到达网址根,然后使用完整路径,如

If so, use a slash to get to the url root and then use the full path from there like

<?php echo '<img src="/images/my_image.jpg">; ?>

否则你的网址很容易搞砸。

Otherwise your urls can be messed up easily.

这篇关于在PHP中使用required / included文件作为基本目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆