ryanborum's avatar

Two File Uploads Within a Form

Hey all, I have a simple form written to accept a date and two files and store them in a database. The database has fields for an id, a date, two filepaths(varchar), and the standard created/updated timestamps. My page follows the basic CRUD model/functions. When I go to submit my form to create a new entry, I get the error: ** Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)** The 'problem' line is : 'agendaPath' => $request->file('agenda')->store('uploads')which should both store the file in a folder called uploads and save the filepath to the "agendaPath" field in the DB.

I have my php_fileinfo extension enabled in my php install, so I'm not sure how to resolve this. My form/view looks like:

    <form action="/agendas" method="post" enctype="multipart/form-data">
    {{ csrf_field() }}
    <div class="form-group">
      <label for="meetingDate">Meeting Date</label>
      <input type="date" class="form-control" name="meetingDate">
    </div>
    <div class="form-group">
      <label for="agenda">Agenda File</label>
      <input type="file" class="form-control" name="agenda">
    </div>
    <div class="form-group">
      <label for="minutes">Minutes File</label>
      <input type="file" class="form-control" name="minutes">
    </div>
     <input type="submit" class="btn btn-primary">

My Route looks like:

Route::resource('/agendas', 'AgendasController');

My Model looks like:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Agenda extends Model
{
  protected $table = 'agendas';

  protected $dates = ['date', 'created_at', 'updated_at'];

  protected $fillable = ['date' , 'agendaPath', 'minutesPath', 'canceled'];
}

And the function from my controller is:

public function store(Request $request)
  {
      $request->validate([
          'meetingDate' => 'required',
          'agenda' => 'required',
          'minutes' => 'required'
      ]);

      $agenda = Agenda::create([
        'meetingDate' => $request->date,
        'agendaPath' => $request->file('agenda')->store('uploads'),
        'minutesPath' => $request->file('minutes')->store('uploads')
      ]);
      return redirect('/agendas/'.$agenda->id);
  }

I'd appreciate any insight you all have. Thanks!

0 likes
3 replies
martinbean's avatar
Level 80

@ryanborum Well, as the error message suggests, is the php_fileinfo extension enabled?

1 like
Cronix's avatar

Create a route to see the phpinfo

Route::get('/phpinfo', function() {
    phpinfo();
});

Then visit the url and see if your extension is actually enabled. You can just search the page for "fileinfo", which should show something like

fileinfo support    enabled
version     1.0.5
libmagic    522 

Be sure to remove the route when done.

1 like
ryanborum's avatar

Wow, this is embarrassing. I was testing my site locally using the artisan command for local php hosting, but I was changing the php.ini for my IIS PHP install. Yikes

Thank you both for helping me realize this

Please or to participate in this conversation.