Laravel

How to upload files in laravel?

How to upload files in laravel?

It’s very simple and ease to upload files in laravel like php. We have laravel own functions which helps us to upload the files.
Let me teach you how to upload and move the image or any kind of files using laravel.

Just follow below few steps to upload an file.

1. Set routting.

My routes.php page

 2. Write Html Code

My files.blade page (view/pages/files.blade)

 3. Write Function to upload and move

My FilesController.php (Controller/FilesController.php)

 



Let me share some builtin Laravel File Functions:

To Get uploaded file : $file = Input::file(‘image’);

To check if file uploaded or nor : if (Input::hasFile(‘image’)) { }

To check valid upload file : if (Input::file(‘image’)->isValid()) { }

To move upload file : Input::file(‘image’)->move(‘yourpath’);
                                     Input::file(‘image’)->move(‘yourpath’, ‘your new file name’);

To get file uploaded path : $path = Input::file(‘image’)->getRealPath();

To get file original name : $name = Input::file(‘image’)->getClientOriginalName();

To get file extension :  $extension = Input::file(‘image’)->getClientOriginalExtension();

To get file size : $size = Input::file(‘image’)->getSize();

To get MIME type of file : $mime = Input::file(‘image’)->getMimeType();

 

Thanks!. If you like this article don’t forget to share and comment.