我想将具有类似结构的远程服务器中的文件复制到具有相同结构的服务器中的文件。
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时,复制文件的代码工作得很好。但是,当我使用数组用一行捕获所有城市名称时,它不起作用。有任何想法吗?我很感激任何帮助,谢谢!
答案 0 :(得分:0)
您正在搜索:
$source = "http://www.remoteserver.com/data/{$city}/";
$dest = "/alltxts/{$city}/";
file_put_contents($dest, file_get_contents($source));
确保您具有在/alltxts/'
中保存文件的适当权限。同样领先的/
对我来说也很奇怪。你的意思是alltexts/
(相对路径)吗?