Jump to content

[SOLVED] require_once path help.. should be easy...


Jonotron

Recommended Posts

Hi,

I have a fairly strange folder structure but I'd like to keep it this way.

I have an error in one file saying "no such file/directory blah blah..." but it should work.  The php file is at /root/admin/ and is asking to access a file at /root/include/  In dreamweaver it can open the other file using the quick link thing but on the page it doesn't work. I'm thinking it has to do with a open_basedir or set_include_path or just something to do with relative paths.  I've been googling for hours and I can't seem to find the answer!

 

simple require function:

require_once '../include/database.php';

 

Any help is appreciated

Sure,

 

__FILE__ = the full path and name of the current file

dirname() function extracts the path from the given parameter

 

result is the path of the current file your in. :)

 

EDIT: just remember the resulting path doesn't have the leading slash so you need to add it ;)

 

ie

__FILE__ // return /root/testing/myfile.php

dirname("/root/testing/myfile.php"); // returns /root/testing

 

so

dirname(__FILE__); // returns /root/testing

so add the  / at the end

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.