Answer the question
In order to leave comments, you need to log in
How to organize photo preloading via Ajax when the profile hasn't been created yet?
When choosing a photo in the user creation form, this photo must be sent to the server via Ajax even before the form itself is sent. This I know how to do. But what to do with it on the server? After all, the user has not yet been created? What to bind it to and where to store it until the rest of the form is received. After all, as I understand it, the path to the photo is stored in the database, but the user is not in the database yet. Tell me the way itself, how to organize intermediate storage and then attach a photo when the form is received.
Answer the question
In order to leave comments, you need to log in
As an option, upload a photo to the server via AJAX, regardless of the user (i.e. without being tied to a specific user),
get the url of this photo from the server,
then substitute this url in a (hidden) form field,
then send it with the rest of the data to the server.
+ after creating a profile, you can create a link to the user id in the database, in the table where the url of this photo is stored.
The last point assumes that in the table where the photo url is stored, there is a user_id field referring to the user.
Once a day (or whatever is more convenient for you), select the entries for which it is empty and delete the files.
It misses the fact that, ideally, there should be an uploaded_at field so that during the cleanup script, you don’t accidentally delete the photos of those users who have currently uploaded a photo, but have not yet finished creating a profile.
Those. compare file upload times and delete those that were uploaded some time ago and have no owner ( user_id ) specified.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question