Upload image or pdf file directly into database table

Chris Blair 03 Dec, 2010
Dear All,
I am making some assumptions (using my very limited knowledge) around uploading files and would like to check that out, and pose a question based on the same. Am I right in saying that the file upload (regardless of file type) is uploaded into a specified directory on the system, but the value stored in the database table field is merely the file name which can be used as necessary? That being the case my question is this...Is it possible to upload a pdf or other image file directly into the database table field which would be of type blob, and if so how can I achieve this? The reason I ask is that I have a table which, to all intents and purposes works just fine and does what I need it to. I have also created a system on my iPhone whereby I can connect directly into the remote database table and manipulate it from the phone. What I need to happen is have any/all image/pdf files that get uploaded into the database viewable on the iPhone connection as well as all the other data that gets presented. The way it is right now is all data is presented as it should be but the image/pdf field displays 'no image available' - which led me to the assumption made at the begining of this email.

TIA and Best Regards

Chris
GreyHead 03 Dec, 2010
Hi Chris,

Your asumption is correct. I've never tried to put an image or document into the database though I know it's possible. I image that the easiest way would be to update the record after ChronoForms has saved the other data into it.

Bob
Chris Blair 03 Dec, 2010
Hi Bob,
Thanks for the response......but it has baffled me (nothing new there :-)

When you say update after Chronofoms has saved other data - forgive my ignorance but what does that mean exactly? Another assumption is that CF writes data to the db and the update is automatic, happening at the end of the db transaction. Assuming that is correct how then do I update an already updated record such that it will hold and display the image/pdf file?

Best Regards

Chris
GreyHead 03 Dec, 2010
Hi Chris,

If you use the ChronoForms DB Connection then it will save all the form data in the table and put the results into an object.

You can access that object to get the id of the record that was just created then add an extra MySQL query in the OnSubmit After box to add the image itself. Presumably that goes in as a column type of BLOB. If you Google you can find some code snippets - though most recommend saving just the link :-(

It might be worth running a little test with PHPMyAdmin to make sure that the result is viewable before you go too far down this route.

Bob
Chris Blair 03 Dec, 2010
Hi Bob,
I am kind of running with things on this one and have had a thought I would like to run past you...

Assuming I leave the setup as is and store the pdf/image in the upload folder. Would it be possible to create another field on that table which gets automatically populated with a URL that links to the image/pdf file on the system? I don't know enough to know what is and isn't possible or more importantly where and how to begin going about this but I am excited and my head is running - sorry :-)

Best Regards

Chris
This topic is locked and no more replies can be posted.