Setting default permissions for files uploaded through php script

Posted on 2004-11-15
Last Modified: 2013-12-15
The files uploaded to our webserver (using a php script) have default permissions: rw------- which suggests a umask setting of 0066, whereas our system-wide umask is 0022. The files are owned by wwwrun:www(default apache) and the system is SuSE linux.

How do I set the umask for wwwrun so that the files uploaded will have the desired permissions (rw-r--r-- )

Question by:sandeep_th
    LVL 12

    Expert Comment

    you have to add some script in your php script so that after the uploaded finished than change the umask will do.

    or you can use a crontab to run a chmod to make it change to 644 on every 1hr or so.

    eg. run 'crontab'

    add below in the cron job

    * 1 * * chmod 644 /data/www/*

    so every an hour the crontab will run and all the files inside the /data/www will become 644 mode.

    but the best way is add the chmod script into your php script.

    hope can help a bit :)

    Author Comment

    hmmm ... not exactly what I was looking for....but CAN be a possible solution. But the fundamental issue is how can we change the default umask of the wwwrun user....THAT is not addressed by this solution. Any other ideas?
    LVL 12

    Accepted Solution

    oh I miss understand that you need to add some script or so..

    you can change the default umask of the wwwrun by 'umask -p 033 wwwrun' so every file(s) wwwrun create will be 'rw-r--r--', is that what you need?? I think so :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
    This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now