PHP Server PHP Write file multi-server synchronization program

Source: Internet
Author: User
Tags learn php programming php server php write
The example of this article for everyone to share the PHP file multi-server Synchronization tool, the specific content is as follows

<?phpheader (' content-type:text/html;charset=utf-8 ');//File name: PHP file Multi-Server Synchronization tool//File role: This file is located on the server as the primary server, The server where the other files are located can be diverted or backed up. This article requires a jquery library. You can also chain someone else's//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 ' no files '; exit; } $aFTPServers = Array (' server1 ' = = Array (' strwei.com ', ' FTP user name ', ' ftp password ', ' Open ftp default directory '),//FTP address, username, password, F  TP Open this site when the default directory//' server2 ' = = Array (' Yy.9.je ', ' FTP user name ', ' ftp password ', ' open ftp in 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 allow synchronization");      Continue } if (!file_exists ('. ').        $v)) {$iError = $iError + 1; Array_push ($aErrors, $iError.        ", file $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 succeeded: '. Implode (', ', $ASUC);  Exit } Echo Implode ('
', $aErrors); Exit;} $CC = ' \ r \ n '; Echo <<

</span> EOF;? ></pre></p>

The above is the whole content of this article, I hope that you learn PHP programming help.

The above describes the PHP server PHP file Multi-server synchronization program, including the content of the PHP server, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.