Search code examples
phpexecfile-permissionspsexec

using exec command in php doesnt work


I have to automate a process using php in which I have to append content in a file. The file does not have any specific permissions specified but the folder 'abc' has read only permissions, so fopen() prompts permission denied when I try to append a file.

But I can edit the file manually and also from the command prompt. So I tried the following:

When I try echo exec("echo Testing>>\\xx.xx.x.x\C$\abc\test.txt"); in my script, it does not work.

If the same command echo Testing>>\xx.xx.x.x\C$\abc\test.txt is run on cmd it works.

I even tried psexec:- echo exec('C:/psexec \xx.xx.x.x cmd /c \"echo Testing>>C:\abc\test.txt\"'); again when i run C:/psexec \xx.xx.x.x cmd /c "echo Testing>>C:\abc\test.txt" on cmd it works fine.

Is it anything to do with exec() that I am doing wrong? OR Is there any other way I can edit file, because I should not change the folder permissions but still get the process automated.


Solution

  • I assume you are using Windows. On Debian Linux, I would tell you to give write permissions to user www-data on the appropriate directory.

    You probably need to give the local IIS worker account write permissions on the directory. The local IIS worker account is likely named something like IUSR_[SERVERNAME].