Support the ongoing development of Laravel.io →
posted 9 years ago
Requests
Last updated 1 year ago.
0

You upload the file and create a DB record right after file is chosen?

Last updated 1 year ago.
0

Yes, i create a record for the uploaded file. After i save the form with my title i have to link the uploaded file with my new created form record. If i don't save the form the files still exists. How you would handle this?

Last updated 1 year ago.
0

Do you need to create DB record right after the file is chosen and uploaded?
Wouldn't it be better, to create the record only after the form is submitted?
And mainly, do you need to upload the file right after the file is chosen with AJAX?

Last updated 1 year ago.
0

No, but why not? My problem is that the form and the upload has two different endpoints. I need to use an ajax upload to display the upload progress especially for large files.

Last updated 1 year ago.
0

Oh, ok then. I dont know if it is best practice, but I just upload the files right away after user chose one (or more) with ajax to some temp folder (which name I store in the session). I display the preview or whatever, and then maybe add the titles for the files.

Then after the the form is submitted, only then I create the DB records. From the session I retrieve the temp folder name, and move the content of the temp folder (my uploaded files) to final location.

If the form is not submitted, no DB records are created, and the temp folder can be erased by some CRON job after some time.

Last updated 1 year ago.
0

Thank you @TorchSK, this might be a solution. If anyone else has a better one... please tell me. :)

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

divdax divdax Joined 3 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.