Backend Development 3 min read

How to Move Files in Laravel Using File and Storage Facades

This tutorial explains how to move files in a Laravel application, showing syntax and complete code examples for both the File and Storage facades, compatible with Laravel versions 5 through 11, and includes guidance on ensuring target directories exist.

php中文网 Courses
php中文网 Courses
php中文网 Courses
How to Move Files in Laravel Using File and Storage Facades

This tutorial demonstrates how to move files within a Laravel application, providing key examples for moving files between folders and across disks using Laravel's File and Storage facades, compatible with Laravel versions 5 through 11.

Method 1: Using the File Facade

Syntax:

File::move(from_path, to_path);

Example:

Assuming a folder exist under the public directory contains test.png , the file is moved to a new folder move and renamed to test_move.png .

Method 2: Using the Storage Facade

Syntax:

Storage::move(from_path, to_path);

Example:

Assuming a file test.png exists in storage/app/exist , it is moved to storage/app/move and renamed to test_move.png .

Ensure the target directories exist before attempting to move files.

BackendPHPfile systemLaravelfile handling
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.