Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation PHP permissions error.

    Currently I have a function that writes a PHP file to a directory given a random string.

    My write function is as follows:

    PHP Code:
    function write($where$what){
    $myFile $where;
    $fh fopen($myFile'w');
    fwrite($fh$what);
    fclose($fh);

    The only problem with it is, the index.php file that I create in the directory needs to be able to run a password protect PHP script. I don't know how to write a file AND give it permissions. If anyone could help me do that, it would be awesome.

    I need to give the file that the write() function creates permissions... <-- simple form.

  • #2
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    you need to chmod() your file.

    http://us2.php.net/chmod
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."

  • #3
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts
    chmod it to 777

  • #4
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The problem is, it creates a file every time a user submits the form. I know about CHmod, but I don't want to have to CHMod Every Single Form a user submits. That's a lot of work. Is there a way to automate Chmod using PHP? A script with full permissions dropping permissions to a lower file?

  • #5
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts
    If the file that is being created is in a variable, it's simple.

    Code:
    chmod("$myfile", 777);

  • #6
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks so much for that. This problem has been resolved. And in an efficient manner
    Thanks all who helped.

  • #7
    New to the CF scene
    Join Date
    May 2009
    Location
    Bulgaria
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I only suggest removing the double quotes in the provided PHP snippet since it speeds down the PHP parser.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •