In our web applications we struggle with a problem reoccurring constantly. An easy example is a blog post: it has a title, lead & body text and an image. Our UX designers would like to let users upload the image asynchronously. This becomes an issue when you want to create a new post. It isn't persisted yet, so there is no id (for example when you use the id for the path of the image) or you can't put the location of the image as column in the database.
We could create a "tmp" folder for blog posts to which a user uploads an image: but what would you do when the user never persists the post? Or when s/he comes back? What if another user uploads an image to create a new post too?
Is there any good practice around this problem? Our apps are written in php, but I think this doesn't really matter for the subject.