我需要创建一个php脚本,以便它将其复制到服务器上的文件夹中,并且源目录将是另一台服务器。
我正在尝试:
function ftp_sync($dir, $conn_id, $url) {
$remoto_dir = '/web/meusite.site/public_html/uploads/img/'.$url;
$local_dir = '../admin/uploads/img/'.$url;
if ($remoto_dir !== '.') {
if (ftp_chdir($conn_id, $remoto_dir) === FALSE) {
echo 'Change dir failed: ' . $remoto_dir . PHP_EOL;
return;
}
if (!(is_dir($remoto_dir))) {
mkdir($local_dir);
}
chdir($remoto_dir);
}
$contents = ftp_nlist($conn_id, '.');
foreach ($contents as $file) {
if ($file == '.' || $file == '..') {
continue;
}
if (@ftp_chdir($conn_id, $file)) {
ftp_chdir($conn_id, "..");
ftp_sync($file, $conn_id, $url);
} else {
ftp_get($conn_id, $local_dir.'/'.$file, $file, FTP_BINARY);
}
}
ftp_chdir($conn_id, '..');
chdir('..');
}
调用函数:
if ($conn_id) {
ftp_chdir($conn_id,'/web/meusite.site/public_html/uploads/img/'.$url;);
ftp_sync($conn_id, $itemURL);
ftp_close($conn_id);
} else {
echo 'connection to server failed!';
}
页面处于永恒加载状态,什么也没发生