Renaming file while uploading Laravel

Today, We want to share with you Renaming file while uploading Laravel.In this post we will show you php Laravel 6 rename uploaded file keep extension, hear for laravel download file from url to storage we will give you demo and example for implement.In this post, we will learn about php Laravel 6 rename uploaded file keep extension with an example.

Renaming file while uploading Laravel

There are the Following The simple About Laravel 6 Change filename when uploading using store Full Information With Example and source code.

  How To Add Flash Messages in Laravel 6 Session?

As I will cover this Post with live Working example to develop Rename a file before moving it to Directory, so the File uploads in Laravel 6 Single and multiple is used for this example is following below.

Step 1: Create a controller page

MobileController.php

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;

class MobileController extends Controller 
{
	public function mobileDisplay()
	{
		return view('Mobile_list');
	}
	public function processFile(Request $request)
	{
	if (Input::hasFile('file'))
	{
		$file = Input::file('file');
		$destinationPath = '../files';
		$mobile_img_name = rand().time();
		$file ->move($destinationPath, $mobile_img_name);
		echo "Good Luck Your File is Uploaded Successfully!</br>";
	}
	}
}

step 2: create a Laravel Blade view page

Mobile_list.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Laravel 6 Rename file - Free Download Source code</title>
    <link rel="stylesheet" href="http://getbootstrap.com/dist/css/bootstrap.css">
</head>
<body>
	<h1>Laravel 6 Change filename when uploading using store</h1>
	<form action="mobile_uploded" method="post" enctype="multipart/form-data">
	<br><br><br><br>
		<table align="center">
			<tr><td><b>Your File Rename</b></td>
			<td><input type="file" name="file"></td></tr>
			<tr><td>
			<input type = "hidden" name = "_token" value = "<?php echo csrf_token() ?>"></td></tr>
			<tr>
			<td></td>
			<td>
			<input type="submit" name="upload" value="mobile_uploded"></td>
			</tr>
		</table>
	</form>
</body>
</html>

Step 3: Define a Laravel Route

routes/web.php

Route::get('/RenameDisplay','[email protected]');
Route::post('/mobile_uploded','[email protected]');

Web Programming Tutorials Example with Demo

Read :

  Laravel Auth Middleware Example Tutorial From Scratch

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel get uploaded file path.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Reply

avatar
  Subscribe  
Notify of