Why doesn't the following code work?
What I'm trying to do is to use a file which lists the paths to my include files, and then I want to be able to include these files from folder levels that are different from the file where I store the include files paths.
That is if I have my list of paths in
classes.txt and I have it saved in the root folder (/)
Then I wish to access the paths listed in classes.txt from a file located in /css
To do this I must both change the paths inside the classes.txt but also reach classes.txt which is one level below the /css folder.
The code works fine until it is time to require the modified path. Although the path is correct I get this error:
Line 17 is line 17 in the first code block.
If I replace $req_line with the path that fails to open, the require_once statement works. It just doesn't work when the path is stored in a variable.
I'm out of ideas.
I would like either a solution to this problem or an alternate path to accomplish what I'm trying to do.
Any ideas?
best regards
Rythmic
Code:
<?php
$levels_down = 1;
$read_length = 8192;
$inc_file = 'classes.txt';
$prefix = '';
for($i = 0; $i < $levels_down;$i++) {
$prefix .= '../';
}
$filename = $prefix.$inc_file;
$lines = file($filename);
$search = 'classes';
$replace = $prefix . $search;
foreach($lines as $line) {
$req_line = str_replace($search, $replace, $line);
require_once "$req_line";
}
?>
That is if I have my list of paths in
classes.txt and I have it saved in the root folder (/)
Then I wish to access the paths listed in classes.txt from a file located in /css
To do this I must both change the paths inside the classes.txt but also reach classes.txt which is one level below the /css folder.
The code works fine until it is time to require the modified path. Although the path is correct I get this error:
Code:
Warning: require_once(../classes/AbstractPersistency.php ) [function.require-once]: failed to open stream: Invalid argument in D:\dev\web\project\css\inc_all_classes.php on line 17 Fatal error: require_once() [function.require]: Failed opening required '../classes/AbstractPersistency.php ' (include_path='.;C:\servers\xampp\php\PEAR') in D:\dev\web\project\css\inc_all_classes.php on line 17
If I replace $req_line with the path that fails to open, the require_once statement works. It just doesn't work when the path is stored in a variable.
I'm out of ideas.
I would like either a solution to this problem or an alternate path to accomplish what I'm trying to do.
Any ideas?
best regards
Rythmic
Comment