CodeIgniter Laravel PHP Example Javascript jQuery MORE
Need a Website Or Web Application Or Any Help.Contact Us: +91 9437911966 (Whatsapp) Note: Paid Service

How to upload file in Laravel framework PHP


In this example we will discuss about how to upload file in Laravel framework PHP.

We use 3 file for File upload.

  1. uploadfile.php
  2. UploadFileController
  3. web.php

uploadfile.php

<!DOCTYPE html>
<html>
<body>
<?php
echo Form::open(array('url' => '/uploadfile','files'=>'true'));
echo 'Select the file to upload.';
echo Form::file('image');
echo Form::submit('Upload File');
echo Form::close();
?>
</body>
</html>

UploadFileController.php

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class UploadFileController extends Controller {
public function index(){
return view('uploadfile');
}
public function showUploadFile(Request $request){
$file = $request->file('image');
//Display File Name
echo 'File Name: '.$file->getClientOriginalName();
echo '
';
//Display File Extension
echo 'File Extension: '.$file->getClientOriginalExtension();
echo '
';
//Display File Real Path
echo 'File Real Path: '.$file->getRealPath();
echo '
';
//Display File Size
echo 'File Size: '.$file->getSize();
echo '
';
//Display File Mime Type
echo 'File Mime Type: '.$file->getMimeType();
//Move Uploaded File
$destinationPath = 'uploads';
$file->move($destinationPath,$file->getClientOriginalName());
}
}

web.php

<?php
/* |--------------------------------------------------------------------------
| 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('/uploadfile','UploadFileController@index');
Route::post('/uploadfile','UploadFileController@showUploadFile');