Forum Moderators: coopster

Message Too Old, No Replies

Using PHP to CHMOD files?

         

vygbuyhnmj

9:19 am on Jun 15, 2006 (gmt 0)

10+ Year Member



I'm running the latest stable version of php4, and need to chmod a huge list of files.

Right now the files are all in a txt file, I seem to be having quite a few issues trying to get something like this to work.

This code returns: "chmod(): Operation not permitted in..."

<?php
chmod("/somedir/somefile", 0755);
?>

So I thought about using an FTP type of solution that is found on the lastest post at the php website regarding the chmod command, however i'm not good at php, at least enough to modify that code or create my own.

Any suggestions?

omoutop

10:15 am on Jun 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



have you try to chmod() 777 the folder the files are in? After finishing, chmod() the folder again. Perhaps this work

vygbuyhnmj

11:20 am on Jun 15, 2006 (gmt 0)

10+ Year Member



chmod the folder where the file resides that needs to be chmod? If so, it makes this script seem rather pointless, doesnt it?

MattAU

5:53 am on Jun 16, 2006 (gmt 0)

10+ Year Member



No it doesn't make it useless... It works just how you want it to.

chmod("dir_path",0777);

//loop
chmod("files",0XXX);
//end loop

chmod("dir_path",0755);

vygbuyhnmj

6:10 am on Jun 16, 2006 (gmt 0)

10+ Year Member



" No it doesn't make it useless... It works just how you want it to."
- Re-read what I wrote...

If you have to chmod all of the folders that the files are in, then the script is pointless.

Also, I already said that the code you just posted, results in an error.

omoutop

7:45 am on Jun 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can you post the exact error you get?

Your posted error : chmod(): Operation not permitted in...
suggests possible permission issues in folder/file.

thats where the chmod($folder_name) comes in.

Also if the script you are using isn't to big, can you post it here? Perhaps there is some other error that prevents the chmod() to function properly

mcavic

4:00 pm on Jun 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The mode of the directory shouldn't matter. It sounds like it's telling you that the script doesn't have permission to change the permissions, and that would be the case if the script was running as a user other than the user who owns the files.

vygbuyhnmj

8:18 am on Jun 17, 2006 (gmt 0)

10+ Year Member



It sounds like it's telling you that the script doesn't have permission to change the permissions, and that would be the case if the script was running as a user other than the user who owns the files.

- That's right! That's because it runs as "nobody" and thus won't have permissions, thus won't work on just about every non-ded server running apache.

vincevincevince

8:18 am on Jun 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's a common problem. The best solution I've found is to use ftp_chmod()

vygbuyhnmj

9:15 pm on Jun 17, 2006 (gmt 0)

10+ Year Member



That's only for php5.

mcavic

10:55 pm on Jun 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If possible, the process that creates the file should chmod it right afterwards. Otherwise, maybe you can run a script from cron as the proper user.

vincevincevince

2:41 am on Jun 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's only for php5.

No, it runs fine on earlier versions. PHP 5 is needed for ftp_chmod() but see php.net's user comments for a compatible version for pre PHP5.

vygbuyhnmj

3:25 am on Jun 18, 2006 (gmt 0)

10+ Year Member



"If possible, the process that creates the file should chmod it right afterwards."
- How is that possible?

"No, it runs fine on earlier versions. PHP 5 is needed for ftp_chmod() but see php.net's user comments for a compatible version for pre PHP5."
- I said that ftp_chmod is for php5, look at the post right above where I said "That's only for php5".

vincevincevince

9:26 am on Jun 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So you did... and I directed you to this user comment on php.net which you find on the ftp_chmod() page:


rabin at rab dot in

<?php
if (!function_exists('ftp_chmod')) {
function ftp_chmod($ftp_stream, $mode, $filename)
{
etc....
?>

It works perfectly for chmodding files with PHP < 5.