hello there.

bit stuck. I'm trying to move files about after they been processed. Everything works fine except for moving or deleting them after i've made a copy.

I can't even change the chmod!

copy($_SERVER['DOCUMENT_ROOT']."/media/ftpfiles/".$fileName, $newVars['path'].$safeFilename.".".$ext);

copy works fine but the below doesn't at all! The owner of the ftp files is helloandcompany but the files created by copying are owned by apache...

chmod($_SERVER['DOCUMENT_ROOT']."/media/ftpfiles/".$fileName, 0777);
rename($_SERVER['DOCUMENT_ROOT']."/media/ftpfiles/".$fileName, $_SERVER['DOCUMENT_ROOT']."/media/usedftp/".$safeFilename.".".$ext);

any help appreciated!

    The problem is that in most PHP web configurations, your PHP scripts are executed by a web server user, not your login or FTP user account. Thus for files uploaded under your FTP login, you'll probably need to ensure that they have read and write access for all users in order for your PHP web scripts to be able to delete or rename it. And chmod() can only work when executed by the file's owner or a super-user (i.e. root).

    Possible solutions would include changing the umask for your FTP login, creating a shell script that uses su/sudo to run as another user and call that script from your PHP script, or just manually set the permissions on the uploaded files via your FTP interface.

      thanks for the pointers. i'll speak to my hosting company and see what they can do!

      Dan.

        PS: Another option would be to do your file uploads via a web form calling a PHP script to handle the uploads, so that the files start out being owned by the web server user account.

          Write a Reply...