Dasun
Dasun

Reputation: 612

Laravel 5 File Uploading Not Working

I'm new to the laravel 5.4.but I have to create a file uploading system. If it is a PDF or other documents:

  1. Upload them seperatly
  2. delete or download it them seperatly.

As I'm new to laravel I started with this. Can anyone help me to get it functioning properly?

Here is my UploadController

class UploadController extends Controller
{
    public function index(){

        return view('upload.index');
    }

    public function multiple_upload(){

        $files = Input::file('images');
        $extention = $file ->getClientOriginalExtention();
        $entry = new Uploads();
        $entry -> mime = $files ->getClientMimeType();
        $entry -> filename = $files ->getFilename().'.'.$extention;
        $entry -> save();
    }
}

Here Is my Routes

Route::get('upload', 'UploadController@index');
Route::post('upload/uploadFiles', 'UserController@multiple_upload');

Here Is my View index.blade.php

<form action="upload" id="upload" enctype="multipart/form-data" >
    <label>Uplod your Attachments</label>
    <input type="file" name="file[]" multiple="" >
    <input type="submit" >
</form>

Here Is My Migration

 Schema::create('upload_3a12', function (Blueprint $table) {
        $table->increments('id');
        $table->string('filename'); 
        $table->string('mime');
        $table->timestamps();
    });

Hope You will help me lot. Thank you.

Upvotes: 1

Views: 1106

Answers (1)

Victor H. Avelar
Victor H. Avelar

Reputation: 136

You are looking at a field called "image" and you are naming your input field "files" and allowing multiple uploads, so you have to loop over files[], and also I will recommend adding some validation rules to your code.

Upvotes: 1

Related Questions