mkdir function is failing me

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
chexed
Forum Newbie
Posts: 7
Joined: Tue Jun 19, 2007 6:44 pm
Location: Dundalk, Maryland

mkdir function is failing me

Post by chexed »

Prepare yourself, I may be tempted to try offering laughter for trade of your PHP advice.
If you don't want to hear the story, skip right to the problem

Long have I trusted the abilities of the mkdir function and I switched hosting providers, and it now fails me. Ok, so I haven't trusted the mkdir function for that long, since I've only really been programming php for about a month an a half now. But in this time, I've developed a site for ease of publication... After switching to a new hosting company, all of my files containing mkdir no longer work. I need this function to keep my web application functioning swiftly, which is the 'only' reason I've built it. So now, after having probably over a thousand articles I've hand written and finally completing the site (so I thought), I've switched hosting providers and I can't make directories VIA php, only via FTP which DEVOURS too much time out of my hand writing (haha, I know, funny thought) time.

the problem:

The script
<?php
mkdir($_SERVER['DOCUMENT_ROOT'].'/testfolder');
?>
Will not create a folder

My head is thumping, I've been Googling this one problem and searching forums and refining forum searches (CTRL+F) for hours today, which is how I know to provide this information:

Operating system Linux
Machine Type i686
Kernel version 2.6.9-55.ELsmp
PHP version 4.4.7

On top of it all, I keep putting bathroom breaks off for possibly unhealthy amounts of time. Not that that was necessary to inform you of, but now you know this problem is causing me discomfort both mentally and physically. So, I joined this forum with hope someone would remedy H E L P spelled out in desert sand.

THANK YOU IN ADVANCE (All capital letters REALLY reminds me look like one of those phishing emails)

I AM ADUBI ABOBWA FROM NORTHERN SOUTH STATE OF OKHIOWA AND MY PHP NEEDS YOU HELP! PLEASE SEND BANK INFORMATION AND PHOTOCOPY OF VALID DRIVER ID WITH SOCIAL SERCITY SO MY PHP CAN ESCAPE THE TYRANNICAL GOVERNMENT !(just joking of course!) Please do NOT send me this information, or I'll be forced to delete my account, IMMEDIATELY. :)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

if you don't have the correct permissions, you cant do it. Check the folder permissions of the folter you're adding to, and if those are all alowed, talk to your host.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Code: Select all

if(mkdir($_SERVER['DOCUMENT_ROOT'].'/testfolder')){
   print 'Created Directory!';
}else{
   print 'Failed Creating Directory';
}
Its not failing, its returning false.
User avatar
chexed
Forum Newbie
Posts: 7
Joined: Tue Jun 19, 2007 6:44 pm
Location: Dundalk, Maryland

Must be the host problem :(

Post by chexed »

I was so wrong. Apparently, on this server at least, php cannot write to a folder unless it's permissions are set so ALL users can WRITE to the file. I'm not an expert, but isn't that unsafe?
User avatar
chexed
Forum Newbie
Posts: 7
Joined: Tue Jun 19, 2007 6:44 pm
Location: Dundalk, Maryland

Re: Must be the host problem :(

Post by chexed »

chexed wrote:I was so wrong. Apparently, on this server at least, php cannot write to a folder unless it's permissions are set so ALL users can WRITE to the file. I'm not an expert, but isn't that unsafe?
Just wanted to note that I think it's pretty ring ding darn a rooten tooten weird that on one server, the folder permissions only need to be set on group, and on another it needs to be set on all users...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It all depends on the user PHP runs as, and who owns the folder it's trying to drop files into.. (and how they relate to one another.)
User avatar
chexed
Forum Newbie
Posts: 7
Joined: Tue Jun 19, 2007 6:44 pm
Location: Dundalk, Maryland

One last question

Post by chexed »

Any idea how unsafe it would be to have (any) folders with all user "write" turned on?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: One last question

Post by feyd »

chexed wrote:Any idea how unsafe it would be to have (any) folders with all user "write" turned on?
It's not very safe. It depends greatly on the security of your server and your scripts to maintain its safety.
User avatar
chexed
Forum Newbie
Posts: 7
Joined: Tue Jun 19, 2007 6:44 pm
Location: Dundalk, Maryland

RESOLVED!

Post by chexed »

Apparently my PHP permissions are [] when using print "PHP runs under the user: [" . system('whoami') . "]<br>"; phpinfo();

openbase_dir is apparently the culprit. :evil:


oh well. at least we've pin pointed the concern, I really want to thank you for your input, it has alleviated some head pressure. I think your providing of cures should be FDA approved.

I believe I've worked a few things out now... In case someone else has the same problem, I would like to provide some personal experiences with working through this problem:

I found this link
http://codex.gallery2.org/Gallery2:Security - Gives you the information to find out what user/permissions/level PHP runs as (how d'ya like the keywords there?)

Well: I made a folder with all permissions maxed out for everyone, then I created a folder using php with permissions set to be accessible for everyone, because the server wouldn't let me create folders using php where permissions were less than that.

Then: I had it create a sub folder, and I realized that PHP wouldn't create any folder with permissions maxed out, however, it could create folders in folders that it had created itself.

Conclusion: In this case at least, As long as PHP creates the folder, it can create folders within a folder where permissions are 755.
PHP could only initially create folders in other folders that were 0777 permissions
PHP could then create folders within those 0777 at anything with stronger protection than 0755 (I accidentially made 400, and now I can't remove the folder. lol, just wanted to see what would happen)
PHP can still access the 755 files when the root folder is then set to (at least) 755 for higher security, though it did need to be turned (down even though numbers go up for lower security) to 777 for initial creation of the sub folder.

Now: I'm going to tinker some more with the folder permissions to see how high I can get the security on them
I hope that's understandable.
Thank you once again for your help!
Post Reply