开发者

Referncing file locations in a php require

开发者 https://www.devze.com 2022-12-18 09:56 出处:网络
another easy question for someone! on my server i have a location like htdocs/aFolderName/ which contains a file index.php, which references a required file from

another easy question for someone!

on my server i have a location like

htdocs/aFolderName/

which contains a file index.php, which references a required file from

htdocs/aFolder开发者_StackOverflow社区Name/php/

by using the code

<?php require('php/db.php'); ?>

I also have a folder

htdocs/aFolderName/other/

which contains another php file which needs to require the php file located

htdocs/aFolderName/php/

how do i reference this, can i step back a folder?

Thanks!


require('../otherfile.php')


require ('../php/yourFile.php');

:)

Relative pointers to directories:

./ - current directory
../ - parent directory


.

require('./somefile.php'); // current directory
require('../somefile.php'); // one directory back
require('../../somefile.php'); // two directories back
require('../../../somefile.php'); // three directories back
// and on on...

I would suggest you to include your file by prefixing it with document root folder because sometimes if you don't specify that folder, file does not get included, so try like this:

require($_SERVER['DOCUMENT_ROOT'] . '/' . 'yourfolder/file.php');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号