[英]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.