[英]How can I copy a folder to another folder with Laravel?
所以正如标题所说,我正在努力将一个文件夹复制到另一个文件夹
我试过这个但没有结果
编辑:我通过修复 $npath 变量来使其工作,我只是给 url 没有文件夹的名称$npath = $newk->url;
所以最终的代码将是:
public function copyFolder(Request $request)
{
$id= $request->get('oldf');
$new = $request->get('newf');
$document = Document::find($id);
$newk = Document::find($new);
$npath = $newk->url.'/'.$document->nom;
$file= new Filesystem();
if($file->copyDirectory($document->url, $npath)){
return redirect('home');
}
return redirect('home');
}
任何帮助,将不胜感激:)
使用这个 function
function recursive_files_copy($source_dir, $destination_dir)
{
// Open the source folder / directory
$dir = opendir($source_dir);
// Create a destination folder / directory if not exist
if (!is_dir($destination_dir)){
mkdir($destination_dir);
}
// Loop through the files in source directory
while($file = readdir($dir))
{
// Skip . and ..
if(($file != '.') && ($file != '..'))
{
// Check if it's folder / directory or file
if(is_dir($source_dir.'/'.$file))
{
// Recursively calling this function for sub directory
recursive_files_copy($source_dir.'/'.$file, $destination_dir.'/'.$file);
}
else
{
// Copying the files
copy($source_dir.'/'.$file, $destination_dir.'/'.$file);
}
}
}
closedir($dir);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.