Laravel File Upload

To Perform file upload in laravel. we will use following step.

Step 1

Create route for file upload.

Route::resource('fileupload', 'FileController'); Step 2

Create view file inside app/views/fileupload.blade.php

<html>
<head>
<title>Laravel file Upload : Tutsway.com</title>
</head>
<body>
<h3>Laravel file Upload </h3>
<form action="upload_file" method="post" enctype="multipart/form-data">
<input type="file" name="uploadfile" size="20" />
<input type="submit" name="upload" value="upload" /> </form>
</body>
</html>
Step 3

Create anoter view file file inside app/views/fileupload.blade.php.

<html>
<head>
<title>Laravel file Upload : Tutsway.com</title>
</head>
<body>
<p>File Upload Sucessfully.</p>
</body>
</html>
Step 4

Create Controller file file inside app/controllers/FileController.php

<?php
class FileController extends BaseController {

public function index()
{
return View::make('fileupload');
}
public function upload_file()
{
Input::file('uploadfile')->move(public_path().'/upload',Input::file('uploadfile')->getClientOriginalName());
return View::make('successfile');
}
}
?>

Function Reference for file upload

move()

move() method is used to move uploaded file to another location

Input::file('file')->move($destinationPath, $fileName);// Where file is file type name

getFilename()

getFilename() method used to get temporary file name.

Input::file('file')->getFilename();

getRealPath()

getRealPath() is used to retrieving path to an uploaded file.

Input::file('file')->getRealPath();

getClientOriginalName()

getClientOriginalName() is used to retrieving original file name of an uploaded file.

Input::file('file')->getClientOriginalName();

getClientOriginalExtension()

getClientOriginalExtension() is used to retrieving the extension of an uploaded file.

Input::file('file')->getClientOriginalExtension();