Aache 2.0 with subdomains & PHP- directory creation permission problems

Posted on 2005-04-20
Medium Priority
Last Modified: 2008-02-20
I am running Apache 2.0 with subdomains. My application is PHP-based. When a user (anonymouse) uploads a file, the file is placed in a new directory with an owner of "apache". The image processing that is then supposed to occur under GD fails- until I change the directory owner to "site6". I am also using the Ensim Pro control panel under Fedora Core 2. Any way to have those directories set with an owner of site6 upon creation? Does PHP have the capability to set new file/directory permissions?
Question by:Thunnus

Accepted Solution

dougday earned 2000 total points
ID: 13824126
Yep, chmod() - http://us2.php.net/manual/en/function.chmod.php

Try it, but I'm guessing you'll might have problems.  If it doesn't work, I think the quickest solution would be to make the users site1/site2/site3/etc. members of the apache group.  Then, you'll probably be able to do a chown() on the file to change it's ownership to the current user - http://us2.php.net/manual/en/function.chown.php.  If you have problems getting chown() to work (i.e. it still says you don't have permission) then you might have to change the umask for your apache user.  The umask handles the default permissions when files are created.  I'm not sure *exactly* where you'd use it, but php also has a umask() function - http://us3.php.net/umask.  I would guess you'd put it at the top of the page where the files are actually handled after they're uploaded.  I'm thinking you'd probably do something like this:


... handle file upload

foreach($uploaded_files as $file) {
    chown($file, "my_user");
    // if you want only this user to have access this file:
    chmod($file, 0700);

Anyway, I hope that at least gives you some more insight into your problem.
LVL 14

Expert Comment

ID: 15990312
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: dougday

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question