You upload the file and create a DB record right after file is chosen?
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?
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?
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.
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.
Thank you @TorchSK, this might be a solution. If anyone else has a better one... please tell me. :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community