Laravel Redirect::withInput()

16,490

Solution 1

It won't work.

When you redirect something in Laravel it stores $_POST and $_GET in Session to get you data back in the next request. Files comes in a special PHP global var, $_FILES, because they are not really in memory, they are in disk and just some info about them in memory.

Storing those files in Session could cost too much in resources, imagine storing them in the Session you store in database... Yeah, Laravel or Symfony could create a layer to deal with it, looks easy at first sight, but looks like they just decided not to.

So, IMO, if you need them in the next request, move them to a temporary area and Session::put() the info about them, so you can just Session::get() them in the next request.

Solution 2

As mentioned here, there is no straight forward way to do this. A valuable solution might be, saving the file somewhere, upon the upload, and then populating your form, after the redirect, with an additional input field, that contains the information about your previously uploaded file. That way you'll be able to decide on the server side, wether to take the old one (in case there wasn't a new file uploaded) or the new one.

Solution 3

This may work:

return Redirect::back()->with('file', Input::file('file_name');

Solution 4

If you make with form like

Form::text("name",null);

it would be work, try it :)

Share:
16,490
M K
Author by

M K

Updated on July 20, 2022

Comments

  • M K
    M K almost 2 years

    As the title says - I'm trying to redirect back to previous page, with input data, like this:

    return Redirect::back()->withInput();
    

    It works as intended for regular input, but not for files! Is there a workaround for this? So that after the redirect, the previous file is selected again.

  • M K
    M K over 10 years
    That's what I wrote below. Is more of a generic PHP problem and not a Laravel specific one.
  • M K
    M K about 10 years
    JavaScript is not an option in this project :(