surreal
2 months ago
280
2
Laravel

Copy file to storage disk

Posted 2 months ago by surreal

I can't find anything usefull in the docs (https://laravel.com/docs/7.x/filesystem): How do I copy a file from my public folder to another disk ('remoteftp')?

$foldername="devme";
$local_pdf_storage=public_path("/pdf/$foldername");
$mkdir=Storage::disk('remoteftp')->makeDirectory("test/".$foldername; //create folder
foreach( File::Files($local_pdf_storage) as $file){
	$filename=basename($file);
	Storage::copy("$relative_source_dir/$filename", disk('remoteftp')->path("test/$foldername/".basename($file)); 
}

Obviously I fail to define correct target (disk) location. All I could find in the docs:

$path = $request->file('avatar')->storeAs( 
    'avatars', // <--- Foldername oder Filename?
    $request->user()->id, // <--- Why User-ID?
    's3' // <-- Probably Diskname
);

Please sign in or create an account to participate in this conversation.