2

I have the following code:

 mkdir($thumb_dir)

which creates a directory in the proper location, but when I view the permissions it is

Owner : nobody
Group : nobody

I don't have shell access to chown. How do I prevent the user assigned as nobody and how do I delete the folder that I have already made since I don't have permission.

It's a godaddy shared server...

Tim Joyce
  • 4,487
  • 5
  • 34
  • 50
  • And `chmod()` doesn't work. right? did you try creating directories with `exec()` eg `mkdir -p{} -m{}`? – rinchik Apr 08 '13 at 21:45

3 Answers3

1

you can delete empty directories with rmdir().

nobody is the user that runs the apache process. You can't change the owner from within php, nor you can delete the folder using shell access (or make any changes on it whatsoever) without root permissions; you can manipulate it only through php

periklis
  • 10,102
  • 6
  • 60
  • 68
  • Thanks for the tip.. I used the selected answer here to delete the directory and files http://stackoverflow.com/questions/3349753/delete-directory-with-files-in-it. Doesn't resolve my assigned owner issue but if it isn't possible this is a good work around. – Tim Joyce Apr 08 '13 at 21:55
  • ok, if the directory is not empty, I would go with the directoryIterator option in that post, but keep in mind that you need 2 passes to avoid recursion: one to delete all files and one to rmdir all folders (for example by putting them in an array, reversing it and deleting each) – periklis Apr 08 '13 at 21:59
1

This happens because the Web server is run by the nobody user. Therefore, everything you do on the file system will be done with the privileges of nobody.

There is typically no way for you to change anything about that. You'll have to manage with the Apache user being different from the FTP user you have. If you create a directory with PHP, you'll only be able to delete it with PHP (using rmdir() when the directory is empty), and if you create files you will most likely have to delete them from PHP as well.

I suggest that you create your directory structure with your FTP user and keep as little PHP-generated content around as possible because of that.

You can alleviate the symptoms using permissive authorizations (with chmod), but that's generally not a super good idea security-wise.

zneak
  • 134,922
  • 42
  • 253
  • 328
0

Use rmdir($thumb_dir); to delete it.

You cannot change your PHP user on a shared server.

bwoebi
  • 23,637
  • 5
  • 58
  • 79