1

My issue isn't that the folder is getting written, it's the permissions that it's being written with. Here is the code I'm using the write the file:

// check if the file/folder exists
$targetPath = 'files/docmoga/';
if(!file_exists($targetPath)){
   $oldmask = umask(0);
   mkdir($targetPath, '0777', true); 
   umask($oldmask);
}
move_uploaded_file($tempFile, $targetFile);

It's failing on the last line because of permissions. Here are the permissions the folder is being written with:

dr----x--t 2 apache apache   4096 May  4 09:17 docmoga

What might be happening to cause the permissions to being written incorrectly for that folder? If it helps I'm using laravel as a framework which I know shouldn't mean anything.

Jared Eitnier
  • 7,012
  • 12
  • 68
  • 123
jamadri
  • 926
  • 3
  • 17
  • 32

1 Answers1

2

Have you checked what user your script is running under?

Run exec('whoami') in your script and look at the output. It should be apache or a user that has the appropriate permissions to create the folder.

Also try to use the literal octal number 0777 vs a string version '0777'. Taken from https://stackoverflow.com/a/2251293/1133306

Community
  • 1
  • 1
Jared Eitnier
  • 7,012
  • 12
  • 68
  • 123
  • I would think it would be apache since when the folder is written it's written with a chown of apache:apache. Also, the whoami command returned apache. – jamadri May 04 '15 at 15:07
  • That was it. It was because the numbers were in a string format versus literal. Thank you! – jamadri May 04 '15 at 15:17