In this tutorial, you will learn how to copy files from one folder to another folder in your Laravel application.
You can use File or Storage Facade to access file system methods. You should use the copy()
method to copy files from one location to another.
The File Facade just contains some primitive methods that work only with absolute path or relative to your script.
The Storage Facade contains a set of complex methods and is a wrapper for other 3rd party tools. You can use the relative path to a storage folder.
You Can change the default storage folder storage/app
in config/filesystems.php
Copy with File Facade
File::copy(public_path('oldLocation/oldFileName.png'), public_path('newLocation/NewFileName.png'));
Copy with Storage Facade
Storage::copy('oldLocation/oldFileName.png', 'newLocation/NewFileName.png');
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.