Laravel rename file while uploading – The Laravel rename file while uploading is used to rename the file or image during uploading.
Laravel rename file while uploading | with full Example.
Let us understand how to use Laravel rename file while uploading.
Full example of rename file while uploading.
Now here i am going to explain how to rename file during uploading.
Create a controller page and save as [RenameController.php].
Let’s look at a simple example.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Input; class RenameController extends Controller { public function renameDisplay() { return view('Rename'); } public function renameFile(Request $request) { if (Input::hasFile('file')) { $file = Input::file('file'); $destinationPath = '../files'; $filename = rand().time(); $file -?>move($destinationPath, $filename); echo "Uploaded"; } } } |
Then create a view page and save as [Rename.blade.php]
Let’s look at a simple example.
<title>Laravel Rename file</title> |
Route Path:-
Route::get('/RenameDisplay','RenameController@renameDisplay'); Route::post('/rename','RenameController@renameFile');
Storage Folder:-