0

sometimes I receive/downlad .pdf files without the "other" group. I mean -rw-r----- 1 root root 12889 Mar 26 16:41 Document.pdf. I need to work them via php scripts (read, move,...) but I cant do it because the owner is root:root while php script is www-data:www-data. I googled the whole internet but was unable to find a solution. I tried with php internal commands and/or exec(), shell_exec(), system() but the result was a big hole in the water.

This is a piece of code I use. Inverting the order of the operations has no effect

$new_name = str_replace(' ','',$fname);
$new_name = preg_replace('/\(|\)/','',$new_name);

$command = 'sudo cp $full_fname $dir.$new_name';
$copy = shell_exec($command); //, $output, $retval);

$ch_perms = 'sudo chmod a+rw '. $dir.$new_name;
$permiss = exec($ch_perms, $output, $retval);

Even chown has no effect.

Any help will be really appreciated tnx

  • You could try using setgid on parent directory. If you `chmod g+s parentdir` after `chown root:www-data parentdir` then any files and/or folders created will be owned by root and have group ownership of www-data. You may also have to change `umask` to 002. – dcarrith Mar 29 '15 at 21:30
  • Im sorry but it doesnt work. I made all the changes you suggested but... nothing. Well, I didnt change the umask since what I know is that umask is used to revoke permissions, not to set permissions. – Joshua Whopper Mar 30 '15 at 08:56
  • [`umask`](http://en.wikipedia.org/wiki/Umask) is used to set default permissions and it is actually essential to the setup I was describing. You can setgid to make sure the group ownership is set to `www-data` but if umask is set to 022 (which is the default for a lot of Linux distros) that would cause files to be `rw-r--r--` which would not allow writing for users in the `www-data` group. Change `umask` to 002 and the default file permissions would then be `rw-rw-r--` which would be what you want (I think...based on the problem/question you posted). – dcarrith Mar 30 '15 at 14:43
  • Im sorry, you are right. I read the comment of user **librodot at ciberpiula dot net** in [link](http://php.net/manual/en/function.umask.php). – Joshua Whopper Mar 30 '15 at 15:49
  • Im sorry, you are right. I read the comment of user **librodot at ciberpiula dot net** in [link](http://php.net/manual/en/function.umask.php). I made some test on the fly and of course happens what you said when I create a file. My problem is present when I download a file. Chrome sets permissions of the downloaded file to -rw-r----- while Firefox sets to -rw-r--r-- whichever umask I set (always on the fly) so I will do some tests and in case will let you know. – Joshua Whopper Mar 30 '15 at 16:09
  • To be honest, I haven't used [`umask`](http://php.net/manual/en/function.umask.php) from within PHP. I was talking about setting a [system-wide umask](http://stackoverflow.com/questions/10220531/how-to-set-system-wide-umask) for your Linux user. Similarly the `setgid` would need to be used on whatever directory you are downloading things to (i.e. Downloads maybe?). – dcarrith Mar 30 '15 at 18:06
  • I made some investigations and found that the permission philosophy changed due to android. Discussion is still open [link](https://code.google.com/p/chromium/issues/detail?id=409416). Until they dont solve this problem I think there is nothing I can do to solve my problem – Joshua Whopper Mar 30 '15 at 19:16

0 Answers0