CodeIgniter Forums
Image and record, chicken and the egg, which one comes first? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Image and record, chicken and the egg, which one comes first? (/showthread.php?tid=54518)



Image and record, chicken and the egg, which one comes first? - El Forum - 09-12-2012

[eluser]rogierb[/eluser]
Here's the situation.Im converting an old system into CI. This means having to do with some poor decissions made a decade ago. Like images.

In the old system the code checks if images exists on disk. The name is the record id of a specifc table and a number. So we have 123.1.jpeg and 123.2.jpg etc.

I want a reference in the database. This is not a problem.
The problem is error handling while uploading.

I need a record_id before I can store the images. The validation is already completed succesfully or else I wouldnt be able to safe the record.
So how do I get any image upload errors back into the form?

Normally I would redirect to an edit form. This is not possible since the edit form is different to the add form.


Any thoughts as to how resolve this?


Image and record, chicken and the egg, which one comes first? - El Forum - 09-12-2012

[eluser]PhilTem[/eluser]
What kind of data do you store in your table?

I was thinking about: You can create a table row before even showing the upload form. This way you will have a record_id before there is any file uploaded so you will basically only do edits on the row data not an insert.

Does this sound like a good solution for you?


Image and record, chicken and the egg, which one comes first? - El Forum - 09-12-2012

[eluser]lewisp[/eluser]
I don't know how easily you could adopt a new naming scheme, but you could generate a unique hash before inserting anything and use that as the ID (or in a new field) rather than using autoID.


Image and record, chicken and the egg, which one comes first? - El Forum - 09-12-2012

[eluser]rogierb[/eluser]
well... this table is not using a incremented ID but rather a random number between 1000.000 and 100.0000.0000.

When we are done with the record it is deleted and the number is recycled (Dont ask me why, its not my solution:-) )
Because the entire system revolves around this solution I cannot change the scheme.

The data stored in the table is like car info (like a car buying/selling website)

Because of the number recycling I cannot easily create an empty row.

Thank you for your input, the new row idea i like.