Problem uploading file with Laravel Excel

Posted 3 years ago by steveperrycreative

I'm trying to upload a file and add the contents to my database using Laravel Excel. The file is uploaded using a form which posts to my uploadFromCsv method.

When I upload the file I get:

PHPExcel_Reader_Exception in Excel2007.php line 82: Could not open for reading! File does not exist.

My form is:

<form class="form-horizontal" method="POST" action="/ascents/upload">
    {!! csrf_field() !!}
    <div class="form-group">
        <label for="file" class="col-sm-3 control-label">Select CSV File</label>
        <div class="col-sm-9">
            <input type="file" class="form-control" id="file" name="file">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-3 col-sm-9">
            <button type="submit" class="btn btn-default">Upload</button>
        </div>
    </div>
</form>

And my method is:

public function uploadFromCsv()
{
    Excel::load(Input::file('file'), function ($reader) {
        foreach ($reader as $log) {
            $ascent = new Ascent($log->all());
            Auth::user()->ascents()->save($ascent);
        }
    });
    return redirect(route('ascents'));
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.