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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2011
    Location
    Preston, UK
    Posts
    131
    Thanks
    36
    Thanked 0 Times in 0 Posts

    I need to change file ownership with PHP script

    This is a follow on from my previous problem.

    I have now managed, with help, to copy a file to a new file name.
    However, the file is useless for use by the user because it is chown apache.apache.
    I need it to be countrymusic.apache to be usable.

    This is my code up to now:
    PHP Code:
    // CREATE CLUB CODE
        
        
    $number fopen("club_code.txt""r");
        
    $club_code fgets($number);
        
    $club_code += 1;
        
    fclose($number);

        
    $newnumber fopen("club_code.txt""w");
        
    fputs($newnumber$club_code);
        
    fclose($newnumber);
        
        
    $club_code "fr".$club_code;
        
        
    //CREATE NEW CLUB INPUT FILE
        
    if($club_code != '') {
        
            
    $old 'fr_addclub.php';
            
    $new "add_".$club_code.".php";
            
    copy($old$new) or die("Unable to copy $old to $new.");
                }

                   
    //CHANGE OWNERSHIP OF NEW CLUB INPUT FILE
            
    $user_name "countrymusic";
            
    chown($new,$user_name) or print_r(error_get_last()); die(); 
    This is the output of the trap:
    Code:
    Array ( [type] => 2 [message] => chown(): Operation not permitted [file] => /home/countrymusic/countrymusic.org.uk/html/clubs/fr_clubs/fr_admin/register-exec.php [line] => 120 )
    I suspect that the reason is that only ROOT can perform this operation and the script is running as APACHE.

    How can I change to root within the script ???

    Can anybody help, please.
    The MAN, The MYTH, The LEGEND:
    John C
    ________________________________
    Support your local Country Music Club

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    can I ask why you need those ownership perms ? , you should be able to chmod them to 0777 would that not be enough ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Nov 2011
    Location
    Preston, UK
    Posts
    131
    Thanks
    36
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by firepages View Post
    can I ask why you need those ownership perms ? , you should be able to chmod them to 0777 would that not be enough ?
    Thank you very much for asking the question.
    I assumed that I needed to change the ownership of the file, but now realise that chmod 0777 works perfect.
    The MAN, The MYTH, The LEGEND:
    John C
    ________________________________
    Support your local Country Music Club

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,441
    Thanks
    62
    Thanked 537 Times in 524 Posts
    <==== Is still waiting for firepages website to be fixed
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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