Laravel 5.1: keep uploaded file as old input

No, the file input can’t be prepopulated by Laravel or by any software. Your website (and any website) doesn’t and shouldn’t know the local path to the file. Imagine the security risks if they did! You could trick a user into uploading their SSH private key or something.

What you need to do is process the uploaded file regardless, even if there are validation errors.

Then you could either store it in your database with a pending status, or have some unique hash assigned to it, with a matching hash stored in the user’s session. The point is to be able to identify incomplete uploads that belong to this specific user.

Then when you display the form, retrieve those incomplete files either from the session or database, and display the thumbnail next to the file upload. This tells the user that they don’t need to re-upload that file. Just make sure that they have a way to remove it as well in case they changed their mind.

Once the form is submitted correctly then clear the session hash or update the database status to complete; whatever you need to do.

Leave a Comment