当我将一个文件从一个位置移动到另一个位置时
rename('path/filename', 'newpath/filename');
如何将一个文件夹中的所有文件移动到另一个文件夹?试过这个没有结果:
rename('path/*', 'newpath/*');
最佳答案
稍微冗长的解决方案:
// Get array of all source files
$files = scandir("source");
// Identify directories
$source = "source/";
$destination = "destination/";
// Cycle through all source files
foreach ($files as $file) {
if (in_array($file, array(".",".."))) continue;
// If we copied this successfully, mark it for deletion
if (copy($source.$file, $destination.$file)) {
$delete[] = $source.$file;
}
}
// Delete all successfully-copied files
foreach ($delete as $file) {
unlink($file);
}
关于php - 将文件夹中的所有文件移动到另一个文件夹中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2082138/