php - 如何在php中控制相对路径
问题描述
在我的项目中,href 有问题。
我的html页面是a.php,它的代码是:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" type="text/css" href="http://www.ulpin.com /css/bootstrap.min.css">
<style>
dd{word-wrap:break-word;};
</style>
<title>SystemTitle</title>
<script type="text/javascript" src="static/js/jquery-1.7.2-min.js"> </script>
<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
<base target="_self"/>
</head>
<body>
<br/>
<br/>
<br/>
<br/>
<div class="container">
<center>
<a href="active.php" class="btn">ManTest</a><br/><br/>
</center>
</div>
</body>
</html>
但它工作失败。于是我用firefox查看了页面源代码,当我点击static/js/jquery-1.7.2-min.js的href时,它显示:
Not Found
The requested URL /o1ws1v/web/admin/static/js/jquery-1.7.2-min.js was not found on this server.
src 已更改。“/o1ws1v/web/admin/”是自动添加的。
为什么?
我的折叠结构是:
/yjdata/www/www/o1ws1v/web/admin/a.php
/yjdata/www/www/o1ws1v/web/static/js/jquery-1.7.2-min.js
/yjdata/www/www/o1ws1v/web/static/js/bootstrap.min.js
否则,a.php 放在 /yjdata/www/www/o1ws1v/web/ 中,它工作正常
谁能帮我?
解决方案
这是一个简单的路径问题。
当您处于/yjdata/www/www/o1ws1v/web/admin/a.php
使用src="static/js/jquery-1.7.2-min.js"
状态时,会发生这种情况:
--/yjdata/www/www/o1ws1v/web/admin/
| |--- a.php <-- You are here
| |--- static/ <-- This is where the browser think that the static folder exists
|--- static/ <-- This is where the folder really is !
因此,您需要a.php
在 src 路径中上一层楼:
<script type="text/javascript" src="../static/js/jquery-1.7.2-min.js"> </script>
..
指示父目录。
推荐阅读
- twitter-bootstrap - 是否可以将 jsf 与引导程序一起使用
- java - DynamoDB,使用偏移量/限制对 100,000 个文档进行分页的方法?
- java - OpenCV 和 Java,读取图像
- python - os.startfile 错误:FileNotFoundError: [WinError 2] 系统找不到指定的文件:
- elasticsearch - 使用 JAVA 中的日期数学表达式删除弹性搜索上超过 30 天的基于时间的索引会给出 indexNotExists 异常
- javascript - 带有参数的查询不起作用的 Firestore
- javascript - 查询字符串起飞最后一个 ')' 在 url
- neo4j - 如果 2 个节点之间有一个节点,则 Neo4J 深度
- javascript - Ajax 请求 laravel 上传表单有时效果很好,但有时会继续加载
- ibm-cloud - 是否可以同时在 Kubernetes Ingress 中使用 web 和 api 类型配置 AppId?