PHP MkDir with set permissions

Posted on 2011-10-30
Last Modified: 2012-05-12
Hi all,

Is there anyway of creating a directory and setting it's permissions?

For example:

mkdir ('myDirectory','0777'); ?


Question by:error77
    1 Comment
    LVL 15

    Accepted Solution

    Yes you can do that.

    However mode is ignored on Windows, setting 0777 will do nothing on Windows box.

    The quotes around 0777 aren't strictly needed.

    If this doesn't work you can always chmod, which will change the permission after the directory has been created.

    mkdir ('myDirectory',0777);
    chmod('myDirectory', 0777);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    The viewer will learn how to count occurrences of each item in an array.
    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.

    760 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

    12 Experts available now in Live!

    Get 1:1 Help Now