Question

Problem:

When I choose the file and submit the form, it goes to the processing page, but apparently doesn't send the file array, just the name of the file.

Goal:

Accept and upload file to appropriate directory.


Environment:

  • Local
  • OSX / MAMP Pro
  • PHP / Laravel 4

Upload Controller:

public function uploadLogo() {
    $locals['route'] = route('saveProfileLogo');
    return View::make('upload_file', $locals);
}

Upload View:

<form method="get" action="{{{$route}}}" enctype="multipart/form-data" class="grid-form">
    <label>File</label>
    <input type="file" name="fresh_file" />

    <input type="submit" class="btn btn-primary" value="Start Upload" />
</form>

Save Controller:

public function saveLogo() {
    // Always fails
    // if (!Input::hasFile('fresh_file'))
        // return 'No file provided.';

    // Always shows: array(1) { ["fresh_file"]=> string(21) "Angular Mountains.jpg" }
    // dd(Input::all());

    Input::file('fresh_file')->move(public_path() . '/files');
    return View::make('upload_file_response');
}
Was it helpful?

Solution

You should use the method="post" in the form, not get, that's why you see the file as a string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top