PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 22nd, 2004, 06:02 PM
UmneyDurak UmneyDurak is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 UmneyDurak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
derictory permissions and uploading files

Hi.
I'm trying to upload a file with php script. Right now in order for it to work I have to set the upload directory to 777 and tmp directory to 777. I'm trying to find more info about why it has too be this way. Also how can I make it so I don't have to set such broad permissions on those directories. I searched online, but really couldn't find anything that explains what I want to know. Can anyone point me in the right direction?

Thx.

Reply With Quote
  #2  
Old July 23rd, 2004, 04:20 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
First off do you know what permission settings 777 means? Don't want to be patronizing but want to make sure you get a full answer.

-KM-

Reply With Quote
  #3  
Old July 24th, 2004, 03:34 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Stop your online search... you will only get more confused. Unix systems differ so much that you will only get so far with online sources.

Your best bet is to learn and understand *nix permissions in full.

Here is an overview quickie -

1 - For files and directories (a directory is just a file w/ a different bit mask) - you have an owner (o), a group (g), and ALL Others (a)

2 - The owner is usually the user that created the file - Understand that user does not = person all the time - user can be a program or script or the system itself

3 - The owner can always override any permission set on the file - in other words, if you are the owner of a file and you remove your own permission to the file, you can always fix it

4 - The group is a set of users that can operate on a file. Group members can do as much as the owner allows them to

5 - All others is everyone else not in the first two categories

6 - A file has permission levels: Read (r) - Write (w) - and Execute (x)

7 - Read means one can open, print (less, cat, more)

8 - Write means one can edit, delete, etc

9 - Execute means one can run the file if it is a program or a script - execute permissions on a directory means the directory is browsable (ls, dir, cd).

Read (r) = 4, Write (w) = 2, Execute (x) = 1, thus 7 means rwx permission.

Given the above, 777 means rwxrwxrwx

This is usually not a good idea. In most cases, I have found that if the "ALL OTHERS" (a) section is filled, something is not setup optimally.

What I mean is, if you setup your ownership and group levels correctly, there should be no need to make your file world read/writeable. Only the owner and group members should have access.

For web applications this is more than true -
Lets take as an example a content management system.
You are a web developer and you decide to write a quick and dirty CMS so your client can edit a couple html pages on his/her own.

The files should be secured so that unauthorized users, even users on the same machine should not have access to this user's web files

The user should be able to do the following:

a. Login by FTP and manage files
b. Login by telnet/ssh and manage files
c. Login by CMS and manage files

Lets start with (a) -
You need a user account that has ftp access. Normally this consists of adding a user "testuser", then add this user to the ftp group so he/she can login using an ftp client.

Depending on your server setup, you may or may not have to do something specific to give the user shell access.

Now the hard part. How to allow this user to edit files through the browser?

Well, the first step is to set all the desired files to be edited so that the owner is "testuser"

You also want to find out what user your web server is running as (usually www, apache, nobody).

Lets say it is www.

cd /directory/of/files
chown testuser:www *

Now you need to make it so the owner and group can edit files, while nobody else has any access at all -

chmod 660 *

Now, it is painfully obvious why we have the last 0, but why are we using 6 instead of 7?

Well, lets add it up -
Read (r) = 4, Write (w) = 2, Execute (x) = 1

We only need Read and Write permissions for this task. Nothing more.

I hope this quick guide was comprehensive enough to understand. It is important that you use user/group permissions correctly, otherwise, you defeat the purpose of using *nix over MsWin* in terms of security.
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > derictory permissions and uploading files


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT