Current location: Hot Scripts Forums » Programming Languages » PHP » Chmoding files with php...


Chmoding files with php...

Reply
  #1 (permalink)  
Old 02-10-04, 02:51 PM
tsb tsb is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Chmoding files with php...

Hi,

Sorry to keep posting, but when i use:

PHP Code:

<?php 

chmod
("file.php"0666); 
?>
I get the error:

PHP Code:

Warningchmod() [function.chmod]: Operation not permitted in /users/web/blah/web/chmod.php on line 2 

When i use the phpinfo() command it states that it is a Linux server.
The folder file.php resides in is chmoded to 777.

Can someone tell me what i've done wrong please?

Thanks alot.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-11-04, 01:35 AM
gforce gforce is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by tsb
Hi,

Sorry to keep posting, but when i use:

PHP Code:

<?php 

chmod
("file.php"0666); 
?>
I get the error:

PHP Code:

Warningchmod() [function.chmod]: Operation not permitted in /users/web/blah/web/chmod.php on line 2 

When i use the phpinfo() command it states that it is a Linux server.
The folder file.php resides in is chmoded to 777.

Can someone tell me what i've done wrong please?

Thanks alot.
The problem is that your script does not have permission in the directory where file.php resides to change permissions on a file. There are several ways to solve this each has it's own problems associated with it.
1) You can set the permissions on the directory high enough so that php can perform the chmod operation. Most likely this will have to be 777. The problem with this is that anyone will now have access at this level to the directory.
2) You can change ownership of the directory where file.php resides to the user under which your php script executes. This is usually the user "nobody". The problem with this is that unless you own the server sometimes you are not allowed to change the ownership of anything.
3) I have used a hybrid aproach of the first two with good results. You create the directory via a php script. This makes the owner the same as the user under which the script executes. Now you can chmod anything you like including the directory and any files it contains. A word of caution when doing this: If you have to chmod the directory itself to 777, which you most likely will in order to perform the chmod operation on the file, you should chmod it back to something less open like 666 when you are done so that "nobody" can not do whatver they like.

hope this helps,
gforce
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 02-11-04, 10:17 AM
tsb tsb is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
So you are saying that if i use php to create the folder that file.php is in, and then create file.php using php, it will let me chmod it using php?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 02-11-04, 04:23 PM
gforce gforce is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by tsb
So you are saying that if i use php to create the folder that file.php is in, and then create file.php using php, it will let me chmod it using php?

yep

gforce
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 02-11-04, 04:26 PM
gforce gforce is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
btw,

php does not need to create the file file.php, just the folder.

gforce
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 02-11-04, 06:35 PM
tsb tsb is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks, it works fine (i think). I need it to create the file.php anyway, as it happens, so everything's fine.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
100 Web Templates & 10 PHP Scripts for sale! HostersUK.co.uk General Advertisements 0 01-10-04 01:31 AM
php files in a cgi-bin directory epic1231 PHP 7 12-31-03 04:42 PM
need help writing script to let user edit thier html or php files pinochio53 PHP 14 12-15-03 08:26 AM
PHP and TXT files JJSmallballer PHP 10 11-03-03 12:04 PM
writing Excel files through PHP pk_jsp PHP 4 09-28-03 06:42 AM


All times are GMT -5. The time now is 09:51 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.