Page 1 of 1
phpbb question
Posted: Tue Sep 14, 2010 10:21 am
by yacahuma
i notice that when you create a new topic, you can upload files even if the topic has not been created ([pressing submit). What is phpbb doing? is it creating the record in a temp table and then copy the information if the person click on submit? Or it always creates a topic with a pending status? I just have to do something similar and wondering the cleanest way to do it.
Re: phpbb question
Posted: Tue Sep 14, 2010 1:20 pm
by Jonah Bron
Looking at the page source, everything is in one form. The submit, save, preview, and add the file buttons all have different name attributes. The destination script probably checks for the existence of the save button, the preview button, submit button, or the add the file button. If the save button is present, it saves it as a draft. If the preview button is present, it formats the stuff that came in through POST to show you what it looks like. If the submit button is pressed, it saves and publishes the post. If the add the file button is present, it gets the file from $_FILES, and then puts everything from Post back into the right text boxes. There probably isn't any temporary post creation.
Of course, this is just a (educated) guess.
Re: phpbb question
Posted: Tue Sep 14, 2010 2:40 pm
by yacahuma
if I just click on "add the file" , without save, preview, or submit, it has to save the file somewhere. how are these files related to the post that has not being created? It has to be on a temp table or phpbb creates a temp token, right? I am lost

Re: phpbb question
Posted: Tue Sep 14, 2010 9:15 pm
by Jonah Bron
Oh, I see what you're saying. You might find what you're looking for in the PHPBB table schema wiki.
http://wiki.phpbb.com/display/DEV/Tables
Re: phpbb question
Posted: Wed Sep 15, 2010 2:21 am
by jarofgreen
Every user has a session, so relate it to the session, no?
One thing to think of is what happens if the user is writing two posts at once? Same session but you don't want to get files mixed up. Maybe you could do something like include a randomly generated ID key in a hidden field on the form and relate files to session ID and Key ID to stop this happening.
Another consideration is what if user uploads a file then abandons the post ... at some point you are going to want to delete that useless file to reclaim space.
I had a quick look at the phpbb tables but couldn't immediately see how they do it. But phpBb is open source and while you can't copy actual code (unless yours is open source) there's nothing to stop you re-useing ideas ... install phpBB on your server, attach a file, then search the server to see how it's stored! (Do tell us when you find out, now I'm curious.)
Re: phpbb question
Posted: Wed Sep 15, 2010 6:37 am
by yacahuma
well,
They have an attachment table, with a column for orphan. They also have a draft table for the message itself. From the code, they only insert to the attachment table. The only thing I dont see is where to they keep the link between the attachment table and the draft(id_draft).
In my case I will automatically create a draft, get the draft id, and insert the file with a draft id. The draft_id will indicate if the file is orphan or not.
OR the easy way, dont allow uploads until a message is created.
But they are not doing it like that