I want to be able to transfer a php array from one server to another via ftp in the form of a file.
The receiving server needs to be able to open the said file and read its contents and use the array provided.
I’ve thought about going about this two ways, either writing a php file from server 1 with php code of an array then simply loading this file on server 2. However writing the said file is getting tricky when the depth of the array is unknown.
So I though about writing the array to the file json encoded but I don’t know how the second server could open and read the said data.
Could I simply do:
$jsonArray= json_encode($masterArray);
$fh = fopen('thefile.txt' , 'w');
fwrite($fh, $thePHPfile);
fclose($fh);
Then on the other server open the data into a variable:
$data = json_decode( include('thefile.txt') );
Has anyone had any experience of this before?
For first server, connect to second server by FTP and put that file contents into a file
use
file_get_contents()for second server: