Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-21-2013, 12:19 AM   PM User | #1
countrydj
Regular Coder

 
Join Date: Nov 2011
Location: Preston, UK
Posts: 130
Thanks: 36
Thanked 0 Times in 0 Posts
countrydj is an unknown quantity at this point
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
countrydj is offline   Reply With Quote
Old 02-21-2013, 01:45 AM   PM User | #2
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,904
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
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)
firepages is offline   Reply With Quote
Old 02-21-2013, 11:57 PM   PM User | #3
countrydj
Regular Coder

 
Join Date: Nov 2011
Location: Preston, UK
Posts: 130
Thanks: 36
Thanked 0 Times in 0 Posts
countrydj is an unknown quantity at this point
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
countrydj is offline   Reply With Quote
Old 02-22-2013, 12:24 AM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,516
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
<==== Is still waiting for firepages website to be fixed
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


Advertisement
Log in to turn off these ads.