How to update a file externally using PHP

I wanted to create a section to my site where I can update files throughout various folders automatically.

Does anyone have any idea how to build such a script from scratch or use an existing script available on the web?

Do you mean you want to have common page items (like a navigation menu) stored in one place, so that you can edit it there and it will update on all pages? That’s called a PHP include, and is very easy to set up (requires very little PHP).

Not seperate pages. For example I have a script running on multiple servers/domains. I need to update/upload 1 file say new.php located in include/ folder. I would download file from another server and need a program that can upload to specific directory. How can I update it using PHP?

Thanks again!

This is not my area, but as far as I know, you can’t do this with PHP. I’m pretty sure it doesn’t work cross server, and I’m not even sure about between sites on the same server.

It isnt really anything custom. How do software providers do updates for their apps?


You can use cURL
This would require a script on the servers you want to update.
Basically cURL will post values to a script on another server, then that script would take the data that just got posted and write to a local file.

In one of the posted fields put in a big hashed value “key” and make sure that the receiving script checks for the correct “key” before writing to file.

You could also write to multiple files by specifying the file you want written to in the cURL posted values.

Thats how I do it.

Thanks for this! :slight_smile: