What am I missing in this require?

Asked

Viewed 40 times

0

I created a simple structure to train require, but it is showing error. What I am missing ?

Structure, within C: xampp_htdocs SMB\

/file_pasta_Root.php

/pasta_A/file_pasta_A.php

/app/pasta_B/file_pasta_B.php

Archives:

/file_pasta_Root.php
<?php
?>
<p>Eu sou o Arquivo que está no Root</p>
/pasta_A/file_pasta_A.php
<?php
require_once '../file_pasta_Root.php'
?>
<p>Eu sou o Arquivo que está na pasta A</p>
/app/pasta_B/file_pasta_B.php
<?php
require_once '../../pasta_A/file_pasta_A.php'
?>

<p>Eu sou o Arquivo que está na pasta B</p>

So when do I access https://localhost/smb/app/pasta_B/file_pasta_B.php I get a Fatal error, which is wrong ?

_______________
Warning: require_once(../file_pasta_Root.php): failed to open stream: 
No such file or directory in 
C:\xampp_\htdocs\SMB\pasta_A\file_pasta_A.php on line 2

_______________
Fatal error: require_once(): Failed opening required 
'../file_pasta_Root.php' (include_path='C:\xampp_\php\PEAR') in 
C:\xampp_\htdocs\SMB\pasta_A\file_pasta_A.php on line 2

___________

However, I changed the require paths to the one from the File example: file_pasta_A.php and it worked "more or less", but I wonder if this is the best method to fix the problem.

<?php
require_once dirname(__FILE__) . '/../file_pasta_Root.php';
?>
<p>Eu sou o Arquivo que está na pasta A</p>
  • There. The error is right there on line 2.

  • In this case the best approach is to work. That way: require_once dirname(__FILE__) . '/../file_pasta_Root.php'; worked? then wonderful.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.