在PHP中获取资源的方法 [英] Ways to resources in PHP
问题描述
我尝试解决Php中的资源路径问题.在文件header.php
中,我包括脚本和样式表,但是当我从views
目录的文件login.php
中的require_once('../templates/header.php');
时,我会在所有资源上获取404错误代码,因为所有文件都必须位于views
direcroty的子目录中.我该如何解决这个问题?
I try to resolve my problem with resource path in Php. In file header.php
I include scripts and stylesheets, but when I require_once('../templates/header.php');
in file login.php
from views
directory I get 404 error code on all my resources, because all files must be in subdirectory of views
direcroty. How I can solve this problem?
路径:
/var/www/reg/templates/header.php
-标题的路径
/var/www/reg/views/login.php
-登录路径
/var/www/reg/js/script.js
-js的路径
/var/www/reg/css/style.css
-CSS路径
/var/www/reg/js/script.js
- path to js
/var/www/reg/css/style.css
- path to css
推荐答案
根据您的文件结构
header.php内部
inside header.php
尝试这种方式:
<link href="/reg/css/style.css" rel="stylesheet" />
<script src="/reg/js/script.js" ></script>
经过测试,它对我有用.
As I have tested it works for me.
这篇关于在PHP中获取资源的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!