0

I have a file called updateServer.php that has the following code:

$myfile = fopen("http://173.XXX.XXX.XXX/myurl/demo/path.txt", "w") or die("Unable to open file!");

I want to use this file to edit the path.txt file that is placed on another server. Is this really possible as I am unable to do this.

I took help from this : http://php.net/manual/en/features.remote-files.php

PS : I over-writted the files on the same server and was successful in the same.

Jiteen
  • 429
  • 2
  • 6
  • 23

1 Answers1

0

You can't write to URLs with fopen. It only makes GET requests.

You could use the cURL library to make an HTTP PUT request, but you would have to configure the server you are writing to to support PUT requests in that fashion. (Web servers do not by default because it would be insane for any HTTP client to be able to write files to any server).

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • I am a having a Server that I'll be cloning again and again. and there is a config file that I want to change for every Cloned Server using a PHP file placed at my Server. Is there any easy way to do that. As it will be dynamic and I will manually PASTE the Server IP in the text Box and it will change the File placed on that server. – Jiteen Nov 14 '14 at 10:49
  • Sounds like a job for configuration management software such as [Puppet](http://puppetlabs.com/solutions/configuration-management) rather than a custom PHP script. – Quentin Nov 14 '14 at 10:56
  • I am now thibnking of another different logic. I'll create a GUI on my Server and will place my second file 'updateServer.php' on the main server that will be cloned. Every time the server is cloned, the new server instance will also contain the updateServer.php File. And from the GUI of my server I'll send the request using POST, AJAX or cURL etc. What say ? – Jiteen Nov 14 '14 at 11:09