In this Laravel Tutorial, I will let you know how to copy one file from one folder to another with example.
Copying file from one location to another location is very common and general activity that you regularly do on your system with the help of GUI.
And If you are familiar with Linux then there is a command cp
to copy file from one location to another. In Laravel, we can achieve it by using copy
method with File
or Storage
Facade.
You can simply use below syntax to copy file from one path to another, you just need to replace the from_path and to_path to their actual path
File::copy(from_path, to_path);
Storage Facade is another way to copy file from one location to another:
Storage::copy(from_path, to_path);
Let's suppose you want to copy the file 'file1.jpg' from old directory to new directory then you can use below line of code
Storage::copy('old/file.jpg', 'new/file.jpg');