include - PHP: A working file doesn't find other files after inclusion? -
first of all: sorry title. if can make replace it, please since didn't know how name problem in first place. said, there possibly duplicates around, figured need on thing , didn't know search for...
the base site wasn't made me. written in html, inclusions done php , don't way made. getting irrelevant question i'm trying ask here.
the files described here contain more stuff what's written here, problem here that
when requiring file requires file b requires many files, file b can't find files it's looking for.
so let's got directory tree like:
| - project +--- lower.txt | -- stuff | ---- case +------ index.php +------ upper.php | -- gallery +---- main.php +---- config.php +---- miscfunc.php +---- css.php
project\stuff\case\index.php:
<?php include("./upper.php");?> ... <?php include("../../lower.txt");?>
project\stuff\case\upper.php:
<?php require_once("../../gallery/main.php"); ?>
project\gallery\main.php:
<?php namespace gallery; ... // i'm trying debug here... : // -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- // $pathtoscan = "./"; // scan current directory, point /project/stuff/case/ function scanfolder($path) { $array = array(); if ($dir = @opendir($path)) { while (($file = readdir($dir)) !== false) { $array[] = $file; } printf("current directory: %s<br/>\n", dirname(__file__)); printf("document_root: %s<br/>\n", $_server["document_root"]); printf("scan directory: %s<br/>\n<br/>\n", $path); var_dump($array); } } scanfolder($pathtoscan); // -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- // require_once("./config.php"); // these files in gallery namespace require_once("./miscfunc.php"); require_once("./css.php"); ... ... ?>
so... when execute project\stuff\case\index.php get:
current directory: c:\xampp\htdocs\project\gallery document_root: c:/xampp/htdocs scan directory: ./ array(4) { [0]=> string(1) "." [1]=> string(2) ".." [2]=> string(9) "index.php" [3]=> string(7) "upper.php" } warning: require_once(./config.php) [function.require-once]: failed open stream: no such file or directory in c:\xampp\htdocs\project\gallery\main.php on line 44 fatal error: require_once() [function.require]: failed opening required './config.php' (include_path='.;c:\xampp\php\pear') in c:\xampp\htdocs\project\gallery\main.php on line 44
now why happen, , how can working without moving files , preferably without breaking main.php?
i ended changing
require_once("./filename.php");
rows to
require_once(__dir__ . "/filename.php");
still wondering if have been done otherwise...
Comments
Post a Comment