0

I have searched stack overflow and Google for many hours now and cannot find an answer. I have found things that are related but nothing is working.

Here is the code:

$oldmask = umask(0);

if(!is_dir("play")){
    mkdir("play", 0777, true);
    chmod("play", 0777);
}
if(!is_dir("play/playTest")){
    mkdir("play/playTest", 0777, true);
    chmod("play/playTest", 0777);
}

umask($oldmask);

The directory "play" is created fine, however I get this error when it tries to create the "play/playTest" directory.

SAFE MODE Restriction in effect. The script whose uid/gid is 178245/178245 is not allowed to access /a/b/c/play owned by uid/gid 25000/25000 in /a/b/c/script.php

I understand this is a file owner restriction due to safe mode, but why would the user be different when the folder was created in the same script?

I have tried with and without umask and with and without chmod, and many other things but nothing has worked.

Any and all help would be greatly appreciated, thanks.

Nedearb
  • 1
  • 1
  • 1
    Since you're using safe mode, you're still using PHP <= 5.3. Deactivate the safe mode, so simple is the solution. – Charlotte Dunois Sep 17 '14 at 20:23
  • What's your OS (Operating System)? – Kleskowy Sep 17 '14 at 20:23
  • Unfortunately I don't have the ability to turn off safe mode, but why do I need to? I guess I'm wondering why is php creating folders with one owner but reads them as another? The OS I'm using is OSX-Mavericks, but it's kinda irrelevant given I'm uploading the files to a site via ftp. – Nedearb Sep 17 '14 at 21:02

1 Answers1

0

This hacky workaround relies on a safe-mode vulnerability:

(you can recursively create directories if you do it using FTP)

http://php.net/manual/en/function.mkdir.php#104301

code_monk
  • 9,451
  • 2
  • 42
  • 41
  • That most likely works (I haven't tried it), but I'm really more interested in trying to figure out why it's doing what it's doing, rather than finding a hack to work around it. Thank you for the solution though, I may have to use it. – Nedearb Sep 18 '14 at 03:49
  • It boils down to a peculiarity of safe mode. This note tells more, but admittedly it doesn't tell *why* http://php.net/manual/en/features.safe-mode.php#45917. I fully agree, though. If you can help it, you should not implement a hack. You should turn off safe mode – code_monk Sep 19 '14 at 00:00
  • I finally got my site admin to disable safe mode, so all is good now. Too bad no one could find a solution to this quirk... :/ – Nedearb Sep 23 '14 at 02:29