Forum Moderators: coopster
but i did not consider this solution as it's gonna take me lots of time which i don't have! probably this is the best solution but my question is:
is there another way to do this? less time consuming way!
i thought of storing all attachments IDs in a session and once the article is submitted it will perform a query and update all attachments to set the (attachment_article_id) equals to the last inserted id which is the article and the attachments IDs which it will perform the query on will be taken from a session!
this might do it! but i did not feel good about this at all! : ) i don't know why!
so if there is any other way please tell me :)
thanks in advance
so what do u suggest?
I guess one more option would be to not insert the attachments into the database after they are uploaded, but rather just store their new location on the server until you are ready to submit the article, and then you can add everything to the database all at once instead of separately. Try playing around with it, though, and see what you can come up with.
What I would do is associate the images with the user id first, in addition to the article. This way, the user can always manage their own images. Make them create the article first, even if it's not "active." You can then assign images to a given article as you will have the article record ID to store in the attachments table. They can edit it ad nauseum and when it's ready, set it to active (or this can be administrative moderation for the active state.)
¦id¦img_id¦article_id¦user_id¦filename¦directory¦date_added
eelixduppy
i'm not sure where i said i want to creat the relation in the articles table maybe i mixed things up i'm sorry and yes i'm making it in the attachments table so there is a field in the attachment table named like (attachment_article_id) which refers to the id of the article this attachment it attached to
in the beginning i considered sending the attachments IDs in the form and when submitted go update them to attach them to the right article but i was afraid of someone trying to manupilate this since it's being sent in the form
but! when u mentioned it u gave me the idea of how to do it!
i guess am going to do it like this:
when the user upload the first attachment a random number or hash will be created and assigned to the (attachment_article_id) then as he keeps uploading new files they all will take the same random number for this field and once he is done and submit the article a javascript function will call the random number and store it in hidden field then a query will be performed and update all records in attachments table where (article_attachment_id) = the random number
in this case if the user manupilated the random number nothing is gonna happen to other articles or other attachments so he will only be harming his own article and i dont think someone submitting a real article will try to do this ^_^
and as rocknbil said it's not good to leave "orphan records or images" but in this case since there is random number or (hash) set to these records which are (orphan) a mass delete to these kind of records and files can be performed occasionally by the administrator or by the script itself
so i guess there is no problem with what i'm about to do or is there?