我想将具有相似结构的远程服务器中的文件复制到我的服务器中具有相同结构的文件中。
include "../arrays.php";
foreach ($citycode as $city) {
$source = "http://www.remoteserver.com/data/{$city}/";
$dest = "/alltxts/{$city}/";
// EVERYTHING FROM HERE ONWARDS RUNS PERFECTLY, THE PROBLEM IS PROBABLY ABOVE.
function copyr($source, $dest)
{
// Simple copy for a file
if (is_file($source)) {
chmod($dest, 777);
return copy($source, $dest);
}
// Make destination directory
if (!is_dir($dest)) {
mkdir($dest);
}
chmod($dest, 777);
// Loop through the folder
$dir = dir($source);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Deep copy directories
if ($dest !== "$source/$entry") {
copyr("$source/$entry", "$dest/$entry");
}
}
// Clean up
$dir->close();
return true;
}
}
当我使用特定的 $citycode 作为 $city 时,复制文件的代码可以正常工作。但是,当我使用数组用一行捕获所有城市名称时,它不起作用。有任何想法吗?我会很感激任何帮助,谢谢!