doddsey_65 Posted May 5, 2011 Share Posted May 5, 2011 I need to make an attachment system for my forum but i have a big issue. When a user adds an attachment they are added to the server there and then(the way i want it to be so i can have progress bars and such). Then when a user submits their post the content and attachmnet names are added to the database. Simple. But what happens when a user decides not to continue with the post? The attachments have already been added to the server but they arent being used. One thing i can think of is to run a query which checks which attachments are on the server and cross references them with the names in the database. If they are on the server but not in the database then delete the files. However that seems to be quite an intensive way of doing things and adds yet another query to each page load. Any advice or ideas on this? Quote Link to comment https://forums.phpfreaks.com/topic/235563-forum-attachment-system/ Share on other sites More sharing options...
requinix Posted May 5, 2011 Share Posted May 5, 2011 Can you use cronjobs/scheduled tasks? That will require some setup by the person who installs the forum. Quote Link to comment https://forums.phpfreaks.com/topic/235563-forum-attachment-system/#findComment-1210715 Share on other sites More sharing options...
sunfighter Posted May 5, 2011 Share Posted May 5, 2011 Where are the attachments saved? I'd put then into a first temp folder and then when the user submits his post the code that adds to the DB can also move the attachment to a permanent location. All stuff left in the first temp folder are the attachments that were not followed up with a post. Easy to handle and delete or what ever. Quote Link to comment https://forums.phpfreaks.com/topic/235563-forum-attachment-system/#findComment-1210732 Share on other sites More sharing options...
phpSensei Posted May 5, 2011 Share Posted May 5, 2011 Where are the attachments saved? I'd put then into a first temp folder and then when the user submits his post the code that adds to the DB can also move the attachment to a permanent location. All stuff left in the first temp folder are the attachments that were not followed up with a post. Easy to handle and delete or what ever. Your still uploading content to the folder. OP, I think the "Cancel" / "Delete" button can trigger a function that will check if there were any attachments made, find them, and delete them. simple. Quote Link to comment https://forums.phpfreaks.com/topic/235563-forum-attachment-system/#findComment-1210753 Share on other sites More sharing options...
doddsey_65 Posted May 5, 2011 Author Share Posted May 5, 2011 you suggest a button in the admin section that will delete all attachments that arent being used? Quote Link to comment https://forums.phpfreaks.com/topic/235563-forum-attachment-system/#findComment-1210755 Share on other sites More sharing options...
phpSensei Posted May 5, 2011 Share Posted May 5, 2011 you suggest a button in the admin section that will delete all attachments that arent being used? Yeah, but if you dig a little deeper you will get some more problems such as if they close their browser and don't bother to even click cancel. Heres what I would do... If a user decides to upload an attachement I will store in a database table, and each attachement has a POST ID which is assigned to it. When they click submit, you can have boolean field which confirms if the post has been submitted or not, if it has then make sure you update the attachement in the table and set the attachement_submitted field to true. You can also delete the attachement if they click cancel, and run a cron job to everyday at a certain time which will check for all attachement who have the attachement_submitted field set to false. Quote Link to comment https://forums.phpfreaks.com/topic/235563-forum-attachment-system/#findComment-1210759 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.