Current location: Hot Scripts Forums » Programming Languages » PHP » creating directories


creating directories

Reply
  #1 (permalink)  
Old 12-15-03, 05:09 PM
canhelie canhelie is offline
Newbie Coder
 
Join Date: Oct 2003
Location: Irvine, CA
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
creating directories

i'm writing a script that lets users upload files. However, based on some options they can choose, the file will be uploaded into different directories and so I need the script to create the directory and then upload the file. I already have that part working. The part I'm having trouble with is the ownership of the directories created and the file uploaded. For some reason the ownership is set to "nobody". Also, when I used the function mkdir(), i specified that i want the permissions to be +311, but it makes it 711 for some reason. ANyone have any ideas?
Reply With Quote
  #2 (permalink)  
Old 12-15-03, 10:53 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

Did you specify the mode like this?

Code:
mkdir($dir_name, 0311);
You need a prefix zero before '311'.

Also, regarding the chown(), you need to specify either user name or its uid, which means this user has to exist on your server. In addition, it has to be a superuser in order to use chown() to change the file owner to whom other than 'nobody' or 'Apache' or whatever the default is or you'll get an error message like "operation not permitted".

Hope this helps.
__________________
Blavv =|
Reply With Quote
  #3 (permalink)  
Old 12-16-03, 04:19 PM
canhelie canhelie is offline
Newbie Coder
 
Join Date: Oct 2003
Location: Irvine, CA
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
hello, thanks for the reply. yes it does help. So if the script is not owned by a superuser, then there is no way of chowning a file or directory?

When I create a file or directory, how come the ownership is "nobody"? shouldnt the owner be the same as the owner of the script that created the file or directory? Because of this problem, I can't delete any of the files or directories my scripts create using FTP, I have to secure shell into my server using my root account to be able to remove these files and directories. any way around this?
Reply With Quote
  #4 (permalink)  
Old 12-16-03, 10:07 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi again,

Quote:
So if the script is not owned by a superuser, then there is no way of chowning a file or directory?
A good explanation can be found on PHP.net (http://ca.php.net/chown) I quote it below:

Quote:
Originally Posted by njs+php at scifi dot squawk dot com
If you allow sudo execution for chmod by "nobody" (www, webdaemon, httpd, whatever user php is running under)in this manner, it had better be a system on which the owner is able to be root and no one else can run code, else your whole system is compromised. Someone could change the mode of /etc/passwd or the shadow password file.

Other system commands (sudo mount) and so forth are similar.
Regarding mkdir()-created file, it does not belong to your username (UID) because it is created by the script excuted by - it could be anybody. As far as I am aware, the only way for the server to know for sure that it is created by you (hence the file belongs to you) is when you login to your account and create a file there.

Hope this gives you the idea.
__________________
Blavv =|
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
error when creating database tables with php script spiroth10 PHP 4 01-06-04 03:59 PM
Creating a simple Guestbook Mickells23 ASP.NET 1 11-14-03 09:46 PM
creating a php registration page codeguru21 Script Requests 3 11-07-03 01:02 PM
Creating sessions geneane ASP 10 10-06-03 08:23 PM
Creating directories and files cobalto2060 PHP 1 08-17-03 03:20 PM


All times are GMT -5. The time now is 07:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.