Juliette
Juliette

Reputation: 1026

PHP require folder above

I have a file structure that looks like this (unimportant files left out):

Testserver
    -file.php
    PHP
        -functions.php
    Administration
        -index.php

Now when I try to call require_once('../PHP/functions.php'); inside the "index.php" it doesn't work and I don't understand why. Anyone an idea what the problem could be?
This works fine:

require_once('../file.php');

Upvotes: 1

Views: 4065

Answers (4)

Juliette
Juliette

Reputation: 1026

first thanks for all the answers, I found the bug now:
inside the functions.php I require another file and the path to that file wasn't correct when I called it from index.php
So I had to change the path inside functions.php not inside index.php.
Still thanks to everyone for the other suggestions :)

Upvotes: 1

Poiz
Poiz

Reputation: 7617

You have a Folder Structure Like so:

Testserver
    -file.php
    PHP
        -functions.php
    Administration
        -index.php

And then, you are inside of index.php trying to Access the File functions.php, which lives inside of the Directory PHP. Then you need to go up one Directory from the current directory of the index.php File (ie. The Administration Directory) [meaning that you get up to Testserver Folder from theAdministration Folder] and then drill down to the PHP Directory. In code this would mean:

    <?php 
        require_once __DIR__ . "/../PHP/functions.php";

Hope this does it for you.

Cheers & Good Luck....

Upvotes: 0

Chris
Chris

Reputation: 1

Check your privileges on the folder and try:

require_once('../PHP/functions.php')

Upvotes: 0

Sitethief
Sitethief

Reputation: 770

  • Do you get an PHP error, and if what does it say?
  • Check for lowercase/uppercase problems

The following should work correctly:

require_once('../PHP/functions.php'); 

Upvotes: 0

Related Questions