Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.