CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   I need to change file ownership with PHP script (http://www.codingforums.com/showthread.php?t=288019)

countrydj 02-21-2013 12:19 AM

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.

firepages 02-21-2013 01:45 AM

can I ask why you need those ownership perms ? , you should be able to chmod them to 0777 would that not be enough ?

countrydj 02-21-2013 11:57 PM

Quote:

Originally Posted by firepages (Post 1314867)
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.

tangoforce 02-22-2013 12:24 AM

<==== Is still waiting for firepages website to be fixed :thumbsup:


All times are GMT +1. The time now is 10:32 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.