Issue
I am working on a web application that allows you to write notes. I want to add some functionality to allow a user to add attachments to notes, but I have a little trouble figuring out the logic behind it.
I want it to work a bit like webmail or phpBB forum posts. You start a new message. There's a file upload input element there with an "add" button next to it. When you add a file, it is uploaded and you can continue to write your message. When you finally click "submit" it creates the note and associates the uploaded files with it. Here's some ASCII art:
Subject: ______________
Message: ______________
______________
______________
Attachments: some_file.txt
resume.odt
______________ [Browse][Add]
[Save]
But how can I associate the uploads with the note when it is still being written? It hasn't been saved yet. It has no ID. Normally I would add a database table that associates uploaded files with note IDs, but that doesn't work for a note that hasn't been saved yet. What I worry about is, when a user starts to write a new note, adds a file to it and then changes his mind, never saving the note (e.g. closing the browser). I don't want those uploaded files lingering around.
Thanks in advance!
Solution
There are many ways of doing it. Here's the one I prefer at first glance: Generate the "mail ID" when the user clicks on "new mail", then you already have it when he wants to upload something.
A way more experimental idea: Generate a hash of the file (p.e. MD5 with a timestamp or something similar) when he uploads it. When he finally submits the mail, add the hash to the mail and use this as a key to the previous upload.
Answered By - Bjoern Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.