main directory

MAIN

child directory

MAIN/сontent/

the file which contains the line:

content1.txt // file

 images/images1.jpg 

child directory with invoked scripts

MAIN/script/

 $a = '/content/content1.txt'; $a = file_get_contents($a); echo $a; 

Task: To make so that, php executed the following instructions.

 Поиск файла => => Файла нет в текущей директории => => Перейти в родительскую папку => => Искать там => прочитать => выдать содержимое. 

I thought and found 3 possible answers:

1 - use chdir in scripts by condition.

2 - set the absolute path of the form ../content/content1.txt;

3 - write your function to automate the process.

Question Is the 4th option possible?
Maybe there is a ready-made function that fulfills these conditions, or another method.

    1 answer 1

    used 3m options

     class extended { public function rd($path) { $dirpath; $dirchange = '../'; if(file_exists($path)) { $text = file_get_contents($path); echo $text; goto end; } do { if(file_exists($fullpath)){ $text = file_get_contents($fullpath); echo $text; goto end; } $dirpath = $dirpath . $dirchange; $fullpath = $dirpath . $path; } while ($dirpath !== '../../../../../'); if(!file_exists($fullpath)) {echo 'file not exists';exit();} end: } } $etrinity = new extended(); $etrinity->rd();