[英]enable to include parent folder's file in php
The answer is already given but it is not satisfied. 答案已经给出,但不满意。 This is my directory structure and I am trying to include the header.php
in index.php
这是我的目录结构,我试图将header.php
包含在index.php
-my_app
-assets
-js
-my_app.js
-css
-my_app.css
-includes
-header.php
-index.php
-test
-my_test.php
I tried with include '../includes/header.php';
我试着用include '../includes/header.php';
but is not working.I also want to include my_app.js file in index.php file.How can I do that? 但没有用。我也想在index.php文件中包含my_app.js文件,该怎么办?
Try with - 尝试-
include 'includes/header.php';
includes
and index.php
are in same folder. includes
和index.php
在同一文件夹中。
The path will be - ../assets/css/my_app.css
路径将是- ../assets/css/my_app.css
You just need to do include 'includes/header.php';
您只需要include 'includes/header.php';
, but I would recommend doing something like include __DIR__ . '/includes/header.php';
,但我建议您执行诸如include __DIR__ . '/includes/header.php';
include __DIR__ . '/includes/header.php';
. 。
For my_app.js
, use this: include 'assets/js/my_app.js';
对于my_app.js
,请使用: include 'assets/js/my_app.js';
. 。
include 'includes/header.php';
include 'assets/js/my_app.js';
Basically in all operating systems: 基本上在所有操作系统中:
../
to access to a higher level direcotory and then go on with the process in the second item 调用/包含较高级别的文件,对于每个较高级别,您需要使用一个../
来访问较高级别的目录,然后继续执行第二项中的过程 Im Sure you need your header.php, so dont use include (You got no error and no script-break if the include fails. Also im sure you need the header only once ;) 我确定您需要header.php,所以请不要使用include(如果include失败,您不会出错,也不会破坏脚本。还要确保只需要一次header;)
require_once('/includes/header.php');
for CSS/JS use sinply ../
to go one step higher :) 对于CSS / JS,请使用sinply ../
向前迈进一步:)
Br 溴
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.