Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

require_once Inside require_once Creates Path Issue

Tags:

php

I have this condition :

  • a file : /public_html/folderX/test.php has a line : require_once '../functions/sendemail.php'
  • on the other hand, /public_html/functions/sendemail.php has a line : require_once '../config.php'

config.php loads perfectly in this situation.

the problem occurs when I try to add that functions/sendemail.php on file(s) which not in the folderX, for example :

when I tried to add require_once 'functions/sendemail.php' on public_html/test.php I got this error message :

Warning: require_once(../config-min.php) [function.require-once]: failed to open stream: No such file or directory in public_html/test.php

how to make require_once '../config.php' inside functions/sendemail.php works 'independently' so wherever it's included on any files this 'require_once' problem won't occur anymore.

I tried to change into 'include_once' but still doesn't work.

thanks!

like image 491
Saint Robson Avatar asked Jan 14 '23 13:01

Saint Robson


1 Answers

try something like

require_once( dirname(__FILE__).'/../config.php')
like image 168
Antti Rytsölä Avatar answered Jan 23 '23 19:01

Antti Rytsölä