0

I apologise in advance, I have googled & stackoverflow'd this and cannot get to the correct answer I need.

I have the following;

if ($radiobutton == "1"){

    require ("/test/_testpage1.php");

}

radiobutton 2 also doing the same but going to testpage2.php instead. Neither of this is working. But if i move testpage1.php OUT of the /test/ folder it works perfectly fine just in public_html.

if ($radiobutton == "1"){

    require ("_testpage1.php");

}

The above works fine, but in the interest in keeping things tidy & easier for me to manage I wanted to put things in folders.

PLEASE may somebody support on something I am quite clearly missing?

Zoltan
  • 93
  • 7
  • 6
    remove the first slash in your first example, to get a relative path.. ?! – Rizier123 Jul 13 '15 at 20:56
  • My god.. Thank you, I knew it would be something so simple I am missing. – Zoltan Jul 13 '15 at 20:58
  • Rizier123, please.. sorry but i'm noobie in stackoverflow, why you are answer in comments and not in answers? Exist any difference? – Nomad Webcode Jul 13 '15 at 21:03
  • @Oscargeek There are probably already few questions/answers, which explains the difference between relative and absolute paths, which is OP's problem here. (Since I don't have any dupe in my head right now, I didn't searched for it) – Rizier123 Jul 13 '15 at 21:08

2 Answers2

1

if your html root is /var/www/html (for example) when you try to require('/test/somefile.php') are trying to open in /test/ folder not in /var/www/html/test/

you can try this code?

/* without "/" */
require ("test/_testpage1.php");
Nomad Webcode
  • 816
  • 5
  • 9
0

I think it's more safe to use fullpath than relative path, maybe something like :

require 'FULLPATH.DS.testpage2.php'

We can debug it more easily rather than relative path

hiraq
  • 1