# Laravel Move File from One Folder to Another Example (ok)

C:\xampp\htdocs\reset\routes\web.php

```
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
    return view('welcome');
});
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/test', [App\Http\Controllers\DemoController::class, 'moveImage'])->name('test');
Route::get('/test2', [App\Http\Controllers\DemoController::class, 'moveImageS'])->name('test2');
```

C:\xampp\htdocs\reset\app\Http\Controllers\DemoController.php

```
<?php
namespace App\Http\Controllers;
use File;
use Storage;
use Illuminate\Http\Request;
class DemoController extends Controller {
  /**
   * Write code on Construct
   *
   * @return \Illuminate\Http\Response
   */
  public function moveImage(Request $request) {
    File::move(public_path('exist/test.png'), public_path('move/test_move.png'));
    dd('move File dont.');
  }
  /**
   * Write code on Construct
   *
   * @return \Illuminate\Http\Response
   */
  public function moveImageS(Request $request) {
    Storage::move('exist/test.png', 'move/test_move.png');
    dd('move File dont.');
  }
}
```

![](/files/jVM1PLDRLeajFaulvBe9)

## Laravel Move File from One Folder to Another Example

By Hardik Savani May 25, 2020 Category : Laravel![](https://a.vdo.ai/core/assets/img/cross.svg)PlayUnmuteLoaded: 1.17%Fullscreen[![VDO.AI](https://a.vdo.ai/core/assets/img/logo.svg)](https://vdo.ai/?utm_medium=video\&utm_term=itsolutionstuff.com\&utm_source=vdoai_logo)This article will provide some of the most important example how to move file from one folder to another in laravel. this example will help you move files from one folder to another in laravel. I’m going to show you about laravel cut file from one disk to another.

If you require to move file from one folder to another in laravel application then i will help you how to do it in laravel. laravel provide File and Storage facade and their method to work with file system. i will give you both way example with syntax so you can use it.

You can easily move file in laravel 5, laravel 6, laravel 7, laravel 8 and laravel 9 in this post solution.

**Example 1: File Facade**

Syntax:

```
File::move(from_path, to_path);
```

Example:

In this example, i have one folder "exist" with test.png image in public folder. we will move this file to new folder "move" with rename file test\_move.png. so let's see bellow code.

```
<?php  namespace App\Http\Controllers;  use Illuminate\Http\Request;use File;  class DemoController extends Controller{    /**     * Write code on Construct     *     * @return \Illuminate\Http\Response     */      public function moveImage(Request $request)    {        File::move(public_path('exist/test.png'), public_path('move/test_move.png'));           dd('Copy File dont.');    }}
```

**Example 2: Storage Facade**

Syntax:

```
Storage::move(from_path, to_path);
```

Example:

In this example, i have one folder "exist" with test.png image in storage. we will move this file to new folder "move" with rename file test\_move.png. so let's see bellow code.

Read Also: [Laravel Copy File from One Folder to Another Example](https://www.itsolutionstuff.com/post/laravel-copy-file-from-one-folder-to-another-exampleexample.html)

```
<?php  namespace App\Http\Controllers;  use Illuminate\Http\Request;use Storage;  class DemoController extends Controller{    /**     * Write code on Construct     *     * @return \Illuminate\Http\Response     */      public function moveImage(Request $request)    {        Storage::move('exist/test.png', 'move/test_move.png');           dd('Copy File dont.');    }}
```

I hope it can help you...


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learnphp.gitbook.io/learnphp/laravel-advanced/laravel-move-file-from-one-folder-to-another-example-ok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
