Chmod not permitted?

Having uploaded some files via FTP, I’m attempting to change their permissions with FTP. However, I keep getting

Warning: chmod() [function.chmod]: Operation not permitted in...

Any ideas?

Sounds like you have to first change the owner.

To what?

And, would PHP have permission to do that?

Depends on how the server is setup. Either PHP is running under Apache/Server user account. Or it is running as a distinct user. Whether PHP has permission to change the owner is a toss up. Plainly, this is why I prefer Windows’ ACLs over the far too simple Unix/Linux permission scheme.

This should read:

I’m attempting to change their permissions with PHP!

I suspect it may be to do with file ownership, but it looks to me like they all share the same owner…

Getting desperate.

Or the folder doesn’t exist.


if (!is_dir($dir))
mkdir($dir, 0777, true);

Nope, the folder definitely exists…

This should read:
I’m attempting to change their permissions with PHP!

Well, now change it’s permissions with FTP

It needs to be done programatically, not manually. Hence PHP.

No, it doesn’t.

In my application, it does.

Anyone else?

It is not application you’re talking about. It is merely files.

So here is the scenario.

I have a CMS, which includes a Java FTP applet, which enables the client to upload large numbers of files and directories.

Once uploaded, these files/directories are moved and processed using PHP. Currently, isolated files are being processed fine. Files within uploaded directories, however, cannot be processed, as PHP doesn’t have permission to do so. If I manually change the permissions on the parent directory to 777, the PHP script runs fine. However, this needs to be done programmatically.

PHP cannot chmod the parent directory, as it fails with ‘Operation not permitted’.

All directories and files (both those that are processed, and those that won’t process) appear to share the same owner.

This is the situation. Can anyone advise?

Your applet must change permissions after upload.

The only other solution is to switch to another hosting provider/tariff
To get one where web-server runs under user’s account.

‘Operation not permitted’ is a linux error, not a php error, because your PHP isn’t running with enough permission.

You could try to exec(‘chmod 0777 file’) it.

According to my own FTP client, everything is already owned by my user account. Both the processed files, and the unprocessable files.

But I haven’t said a word about files.
webserver it was. software demon that serves user requests

Using exec, no error is thrown - but the permissions are not changed, either.

When the file is uploaded, it is saved by the PHP/ Apache process’ user, not your user. The Apache user does not have permission to chmod in that directory.

What you need to do is change the permissions on the folder to give the Apache user permissions to do stuff in the folder.

You’ll probably need to change the permissions to 755 or maybe even 777. You should only need to do this once though.

After that, Apache should be able to chmod the files it has just saved there after an upload.

If that still does not work, you may need to alter the ownership of the directory/ files.

He’s uploading via FTP, not HTTP. Hence his problem.