Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-09-2013, 01:09 AM   PM User | #1
cgdtalent
New Coder

 
Join Date: Jan 2013
Posts: 35
Thanks: 11
Thanked 1 Time in 1 Post
cgdtalent is an unknown quantity at this point
How do I make directory outside of root?

I want to make directories for users that are located outside the root of the site. These folders will contain files they end up uploading. But I'm realizing right now as I am trying to do it, that I don't know how to do it.

The only way I know how to make directories is within the site itself.

PHP Code:
mkdir("new_folder"0775); 
Can someone tell me how to make a directory above the root?
cgdtalent is offline   Reply With Quote
Old 01-09-2013, 01:17 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Use an absolute path or a relative path and move up above the public_html. If this file is currently located directly under public_html, you can get above there using ../.
Privilege wise you may need to manually create a directory that's sibling to the public_html and assign the additional privileges. If you cannot create in the ~/ directory (assuming public_html is directly below ~), then I wouldn't suggest opening it up. I would suggest creating the adjacent one and adding the necessary permissions to it.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
cgdtalent (01-09-2013)
Old 01-09-2013, 01:37 AM   PM User | #3
cgdtalent
New Coder

 
Join Date: Jan 2013
Posts: 35
Thanks: 11
Thanked 1 Time in 1 Post
cgdtalent is an unknown quantity at this point
I did the following to make a directory named "user1" and it didn't make the directory:

PHP Code:
$file_path "/var/www/vhosts/s15271400.onlinehome-server.com/httpdocs/users/user1";
$result mkdir($file_path0777);
if(
$result) {
echo 
"Success";
} else {
echo 
"Failure";

I set the permissions on httpdocs and panusers wide open and it still didn't make the directory.
cgdtalent is offline   Reply With Quote
Old 01-09-2013, 01:49 AM   PM User | #4
cgdtalent
New Coder

 
Join Date: Jan 2013
Posts: 35
Thanks: 11
Thanked 1 Time in 1 Post
cgdtalent is an unknown quantity at this point
Initially I couldn't even make a directory within the root but then I went into the server and changed the permissions for the folder the site exists in, and now I can at least do that. But even with the file permissions set wide open on /httpdocs/ and httpdocs/users/ it still won't make a directory.

Last edited by cgdtalent; 01-09-2013 at 02:21 AM..
cgdtalent is offline   Reply With Quote
Old 01-09-2013, 02:26 AM   PM User | #5
cgdtalent
New Coder

 
Join Date: Jan 2013
Posts: 35
Thanks: 11
Thanked 1 Time in 1 Post
cgdtalent is an unknown quantity at this point
I got it to finally work. I had to set the open_basedir to allow or include the directory I was creating the folder within. I'm not sure if this is a good thing to do but it worked. But here is the setting before on open_basedir:

{DOCROOT}/:/tmp/

And here it is now:

/var/www/vhosts/s15271400.onlinehome-server.com/httpdocs/:{DOCROOT}/:/tmp/


Does anyone who knows about servers think this is ok?
cgdtalent is offline   Reply With Quote
Old 01-09-2013, 03:32 AM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Is the httpdocs the parent of public_html, or is it the directory in use for serving the http docs out of?
The use should be fine. The purpose of this directive is to force PHP to only open files in specific locations in the filesystem tree. This appears to be tight enough IMO (although I don't know what the {DOCROOT} is); the ones to really watch for are / and . since both of these can be heavily exploited (baring permissions of course).
Another problem I often see with this is the umask as well. Seems to me that you're okay on yours though.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
cgdtalent (01-09-2013)
Old 01-09-2013, 04:53 AM   PM User | #7
cgdtalent
New Coder

 
Join Date: Jan 2013
Posts: 35
Thanks: 11
Thanked 1 Time in 1 Post
cgdtalent is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
Is the httpdocs the parent of public_html, or is it the directory in use for serving the http docs out of?
The use should be fine. The purpose of this directive is to force PHP to only open files in specific locations in the filesystem tree. This appears to be tight enough IMO (although I don't know what the {DOCROOT} is); the ones to really watch for are / and . since both of these can be heavily exploited (baring permissions of course).
Another problem I often see with this is the umask as well. Seems to me that you're okay on yours though.
the directory httpdocs is above the root of the site and is outside of it. Here would be a view of the server at its highest level:

- httpdocs
- site ------> html files in this directory
- private
- cgi-bin

So maybe the site should have been put in the httpdocs folder, but it wasn't. It was placed outside of it. I don't know enough about servers to know if this is ok, but I'm hoping it is.
cgdtalent is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:18 AM.


Advertisement
Log in to turn off these ads.