-1

I'm new to PHP and I'm having a problem with the require_once function.

When I call the function require_once("/a/b/c/d/e.php");, the function crashes although the path is correct for the file.

Does anyone know why this is happening?

melpomene
  • 84,125
  • 8
  • 85
  • 148
  • 1
    `/a/b/c/d/e.php` is an absolute Path. Are you sure you want to use an absolute path and not a relative one? – Fairy Jul 15 '16 at 09:26
  • 1
    What is the error? – rmondesilva Jul 15 '16 at 09:27
  • No need to add just `/` at the start, If want to add then add like `./`. In your case `require_once("./a/b/c/d/e.php");` OR `require_once("a/b/c/d/e.php");` – Shrikant Mavlankar Jul 15 '16 at 09:28
  • 2
    If the path was correct it wouldn't "crash". 1) Convince us why you think the path is correct. 2) Give us the concrete error you're seeing. – deceze Jul 15 '16 at 09:28
  • share both path `path of file which need to be include` and `path of file where you are using this code` ? – Niklesh Raut Jul 15 '16 at 09:30
  • i tried using a relative path by using $DirAct = getcwd(); $DirPrincipal = dirname(dirname($DirAct)); $DirPrincipal= $DirPrincipal."/www/motlle/gen.php"; but it also crashed the path of the files is /home/projei/www/resp/test.php for my actual and /home/projei/www/mot/gen.php for the one i have to include and i know their paths becouse i'm editing them via notepad++ and i'm using it as reference – newbie in php Jul 15 '16 at 09:48
  • and for the error i d'ont recive any message it's just blank and i know the code from gen.php is correct because i have alredy tested it before thats the reason i don't know what to do – newbie in php Jul 15 '16 at 09:51
  • You don't receive *any* error?! Then start by **enabling error reporting** and/or looking at your error logs. Poking around in the dark helps neither us nor you. – deceze Jul 15 '16 at 09:52
  • the errors are activated and i still don't recive anything, i tried creating an error and it is displayed thats why i find it so strange – newbie in php Jul 15 '16 at 09:53
  • may be apache configuration or permissions is not set correctly – Parviz Eyvazov Jul 15 '16 at 10:39
  • Must be i uninstaled apache and re-instaled and it worked thanks for the help :) – newbie in php Jul 18 '16 at 08:23

1 Answers1

0

Include another file in PHP class

try require_once(dirname(__FILE__)."/a/b/c/d/e.php")

Community
  • 1
  • 1
nonybrighto
  • 8,752
  • 5
  • 41
  • 55