Laravel 8 - How to move file from one folder to another folder

Laravel 8 - How to move file from one folder to another folder

In this Laravel Tutorial, I will let you know how to move one file from one folder to another with example.

There are some common and general activity that you usually do on your computer and moving files from one location to another is one of them.

If you are familiar with Linux then there is also a command mv to move file that needs source and destination. In Laravel, we can achieve it by using move method with File or Storage Facade.

Move file using File Facade

You can use below line of code to move file from one path to another, you just need to replace the from_path and to_path to their actual path

File::move(from_path, to_path);
Move file using Storage Facade

You can also use Storage Facade to move file:

Storage::move(from_path, to_path);

Let's suppose you want to move the file 'file1.jpg' from old directory to new directory then you can use below line of code

Storage::move('old/file.jpg', 'new/file.jpg');

Phone: (+91) 8800417876
Noida, 201301