This article examples for you to share the PHP file multi-server synchronization tool, specific content as follows
<?php header (' Content-type:text/html;charset=utf-8 '); File name: PHP file Multi-server Sync tool//File function: This file is located on the server as the primary server, other files on the server can be diverted or backup. This article requires a jquery library.
You can also outside the chain of others//last modified: 2016-06-30//by:strwei if (!empty ($_post[' files ')) sync ();
function sync () {$aFiles = explode ("\ n", $_post[' files ');//var_dump ($aFiles); exit;
foreach ($aFiles as $k => $v) {if (strlen ($v) <= 5) unset ($aFiles [$k]);
} array_filter ($aFiles);
if (empty ($aFiles)) {echo ' does not have a file '; exit; $aFTPServers = Array (' Server1 ' => array (' strwei.com ', ' ftp username ', ' ftp password ', ' open ftp in default directory '),//FTP address, username, password
, FTP Open this site when the default directory//' Server2 ' => array (' Yy.9.je ', ' ftp username ', ' ftp password ', ' open ftp in the default directory '),);
$aAbortFile = Array (' robots.txt ');
$aErrors = Array ();
$iError = count ($aErrors);
$aSuc = Array ();
foreach ($aFTPServers as $ftp) {$conn = Ftp_connect ($ftp [0]);
if (empty ($conn)) {$iError = $iError + 1; Array_push ($aErrors, $iError.
", Server $ftp Unable to connect");
Continue
} $login = Ftp_login ($conn, $ftp [1], $ftp [2]);
if (empty ($login)) {$iError = $iError + 1; Array_push ($aErrors, $iError.
", server $ftp [0] cannot log in");
Continue
} $ftp _root = ';
if (!empty ($ftp [3])) $ftp _root = Ftp_chdir ($conn, $ftp [3]);
$ftp _root = ftp_pwd ($conn);
if (substr ($ftp _root,-1) = = '/') $ftp _root = substr ($ftp _root, 0,-1);
foreach ($aFiles as $k => $v) {$s = basename ($v);
if (In_array ($s, $aAbortFile)) {$iError = $iError + 1; Array_push ($aErrors, $iError.
", file $v not allowed to sync");
Continue if (!file_exists) ('. ').
$v)) {$iError = $iError + 1; Array_push ($aErrors, $iError.
", the document $V does not exist");
Continue
$upload = Ftp_put ($conn, $ftp _root. $v, '. '. $v, ftp_binary);
if (empty ($upload)) {$iError = $iError + 1; Array_push ($aErrors, $iError.
", File $v upload failed");
Continue
} array_push ($aSuc, $v);
} if (empty ($aErrors)) { Echo ' Upload success: '.
Implode (', ', $ASUC);
Exit
echo implode (' <br> ', $aErrors);
Exit
} $cc = ' \ r \ n ';
Echo ' <script src= '//cdn.bootcss.com/jquery/3.0.0/jquery.js ' ></script> '; echo <<<eof Please enter the name of the file (including its path) you want to sync, for example: Inoutcome_final.zip,/default.php,/index.php,/inoutcome_ Final.sqlite, etc., enter a filename per line, enter multiple <br><br> <textarea style= "width:450px; height:85px; border:1px #000 solid; "id=" Id_file "onkeyup=" this.value=this.value.replace (//g, ""); ></textarea><br> <button id= "Btn_submit" onclick= "return Submit_sync ();" > Sync above file </button> <br><span id= "Show_sync" style= "color: #f00;"
></span> <script> function Submit_sync () {$ ("#btn_submit"). Hide ();
var sfiles = $ ("#id_file"). Val ();
var afiles = sfiles.split (/$CC/);
if (afiles.length <= 0 | | | | afiles[0].length <= 5) {alert ("Please write the list of files to sync manually");
$ ("#btn_submit"). Show ("slow");
return false; } $.post ("?", {"Files": Sfiles}, Function (V) {$ ("#show_sync"). Text (v);
if (V.indexof ("Upload success")!=-1) $ ("#id_file"). Val (');
$ ("#btn_submit"). Show (5000);
}) return true; } </script> EOF;?>
The above is the entire content of this article, I hope that you learn PHP program help.