0

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.

Tinasm
  • 82
  • 1
  • 1
  • 6
  • Your app will need write permissions or no, you cannot accomplish this. And using `exec` attempting to work around that is a terrible idea (sorry). – Madbreaks Oct 19 '12 at 17:49
  • PHP is running as a different user with different permissions than your user. So it is unlikely that you are going to able to circumvent the file permissions. – Doon Oct 19 '12 at 17:50

2 Answers2

0

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].

Matt
  • 556
  • 1
  • 4
  • 18
0

Some webhosts decides to remove the function exec for security reasons.

view your php info and check if yours is disabled.

Makkesk8
  • 152
  • 1
  • 3
  • 13