WEB DEVELOPER SITE
TUTORIALS HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Laravel - File Uploading

Laravel - File Uploading : You have to make a view document where a client can choose a record to be transferred and a controller where transferred documents will be processed.

First you have to create a record contribution by including the accompanying line of code.
Form::file('file_name'); 

Form::open(), we have to include 'files'=>'true' as appeared as follows. This encourages the structure to be transferred in numerous parts.
Form::open(array('url' => '/uploadfile','files'=>'true')); 

Example

Step 1 − A view document called resources/sees/uploadfile.php and duplicate the accompanying code in that file.

resources/sees/uploadfile.php

<html> 

<body> 

<?php 

reverberation Form::open(array('url' => '/uploadfile','files'=>'true')); 

reverberation 'Select the record to transfer.'; 

reverberation Form::file('image'); 

reverberation Form::submit('Upload File'); 

reverberation Form::close(); 

?> 

</body> 

</html> 

Step 2 − A controller called UploadFileController by executing the accompanying command.

php craftsman make:controller UploadFileController - plain 

Step 3 − After effective execution, you will get the accompanying yield −

UploadFileController

Step 4 − Copy the accompanying code in

app/Http/Controllers/UploadFileController.php file.

app/Http/Controllers/UploadFileController.php

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 

use App\Http\Requests; 

use App\Http\Controllers\Controller; 

class UploadFileController broadens Controller { 

open capacity index(){ 

return view('uploadfile'); 

} 

open capacity showUploadFile(Request $request){ 

$file = $request->file('image'); 

/Display File Name 

reverberation 'Record Name: '.$file->getClientOriginalName(); 

reverberation '<br>'; 

/Display File Extension 

reverberation 'Record Extension: '.$file->getClientOriginalExtension(); 

reverberation '<br>'; 

/Display File Real Path 

reverberation 'Record Real Path: '.$file->getRealPath(); 

reverberation '<br>'; 

/Display File Size 

reverberation 'Record Size: '.$file->getSize(); 

reverberation '<br>'; 

/Display File Mime Type 

reverberation 'Record Mime Type: '.$file->getMimeType(); 

/Move Uploaded File 

$destinationPath = 'transfers'; 

$file->move($destinationPath,$file->getClientOriginalName()); 

} 

} 

Step 5 − Add the accompanying lines in app/Http/routes.php.

app/Http/routes.php

Route::get('/uploadfile','UploadFileController@index'); 

Route::post('/uploadfile','UploadFileController@showUploadFile'); 

Step 6 − Visit the accompanying URL to test the transfer document functionality.

http://localhost:8000/uploadfile