Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » open_basedir and directory structure

This thread is locked; no one can reply to it. rss feed Print
open_basedir and directory structure
Mark Oates
Member #1,146
March 2001
avatar

I want to be able to use files in my base directory from a higher directory and I don't know how.

Maybe I just don't know how to use directories correctly, but the process I want to take is like this: I have at my base directory "head.php" and "foot.php". I want to have an article kept in a directory "articles/spam_safe" that also uses the head and foot.

I read somewhere that all you need to do is put a "/" at the beginning:

include('/head.php');

but that doesn't work. so I tried:

include('../../head.php');

not very elegant, it kind of worked, except it couldn't read the other files like the the css and other php files that included from within head.php.

Warning: main() [function.main]: open_basedir restriction in effect. File(/right_menu.php) is not within the allowed path(s): (/var/www/vhosts/zeoxdesign.com/httpdocs:/tmp) in /var/www/vhosts/zeoxdesign.com/httpdocs/foot.php on line 7

what should I do?

Matthew Leverton
Supreme Loser
January 1999
avatar

echo ini_get('open_basedir') will tell you which folder is your basedir. You should probably add that to your include path in the .htaccess file.

.htaccess:
php_value include_path ".:/my/base/dir"

Once you've added your site's base dir to the path, you can include files relative to that.

Mark Oates
Member #1,146
March 2001
avatar

ok, now it's including the php files but it still doesn't load the css file or images.

Matthew Leverton
Supreme Loser
January 1999
avatar

Define "doesn't load the css file or images." Are you open them from within PHP source code? Or do you just mean they won't show up in the browser?

Mark Oates
Member #1,146
March 2001
avatar

just won't show up in the browser. When the address is

www.zeoxdesign.com/articles/story1.php

and the background, title, etc images are located in

www.zeoxdesign.com/images

they won't display and it looks like this:

{"name":"592195","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/3\/93994408fe87f61e54a17b6fd69031d4.jpg","w":449,"h":456,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/3\/93994408fe87f61e54a17b6fd69031d4"}592195

normally

{"name":"592196","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/3\/d37d3006e61b1bc4b3060f136fa69af0.jpg","w":499,"h":475,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/3\/d37d3006e61b1bc4b3060f136fa69af0"}592196

Matthew Leverton
Supreme Loser
January 1999
avatar

For the images and css and web files, you should just make them all relative to the root.

<img src="/images/foo.png" />

Mark Oates
Member #1,146
March 2001
avatar

just with the backslash at the beginning?

Matthew Leverton
Supreme Loser
January 1999
avatar

Yes. Keep in mind that there are two file systems involved. The first is the physical one. The second is the web one. The web files are relative to your DocumentRoot, which can exist anywhere in the physical file system.

The leading slash in HTML code will cause it to always find the images folder, assuming it exists at $DocumentRoot/images.

However, a leading slash in PHP code will cause it to go to the base system / folder, which is surely not what you are looking for.

Mark Oates
Member #1,146
March 2001
avatar

yay!
http://www.allegro.cc/files/attachment/592197

I understand now. Thanks a lot!

CGamesPlay
Member #2,559
July 2002
avatar

Not technically related, but FYI: / is a slash, \ is a backslash. At least on my keyboard, backslash is below the backspace. Also, one is used for escaping strings in C/php/whatever.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Go to: