The following warnings occurred:
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined variable $newpmmsg - Line: 40 - File: global.php(841) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/global.php(841) : eval()'d code 40 errorHandler->error
/global.php 841 eval
/printthread.php 16 require_once
Warning [2] Undefined array key "style" - Line: 909 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 909 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$lang_select_default - Line: 5024 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 5024 errorHandler->error
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions.php 5044 is_member
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1370 fetch_forum_permissions
/printthread.php 76 forum_permissions
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error



Form Tools
Saving binary file to database - Printable Version

+- Form Tools (https://forums.formtools.org)
+-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1)
+--- Forum: General Discussion (https://forums.formtools.org/forumdisplay.php?fid=5)
+--- Thread: Saving binary file to database (/showthread.php?tid=250)



Saving binary file to database - nomad - Aug 20th, 2009

Hi Ben,
I would like to generate on-line pdf invoice, save it to MySQL and send it by email as attachment.

1/ I am generating pdf file by FPDF, I can save it to disk or show it in a browser, but I could not save it to database.
For processing I use process.php method and Submission Pre-Parser module to generate pdf. As the file is not uploading from web form, I have added manually a Form field "attach" (Field type is set to file) and set a relevant database column to "mediumblob". My code is easy:

...
...
$_POST["attach"]=$pdf->Output('','S');

The script runs without any errors or stops, but database remains empty all the time. A also tried another method - save pdf and upload file from disc then:


$pdf->Output('test.pdf','F');
$filename = "test.pdf";
$fd = fopen ($filename, "r");
$binarydata = fread ($fd, filesize ($filename));
$_POST["fak_priloha"]=$binarydata;

The same results.

2/ Sending e-mail attachments from disc ({$attachment file="test.pdf"}) works but similar {$attachment field="attach"} does not even if I manually upload to database some binary content. I am only able to include binary data to email“s body by {$FILENAME_attach} which is worthless.


Any idea is welcome as I am absolutely stuck.

Thank you.


RE: Saving binary file to database - Ben - Aug 21st, 2009

Hey Nomad,

Regarding #1, no, you won't be able to store binary data in the database... at least I very much doubt it. Form Tools fields are text-based (MEDIUMTEXT, VARCHARS) and binary data should be stored in BLOBs. What I'd do instead is this:
1. save the file directly to a folder somewhere,
2. store the unique filename in the POST request and pass THAT to Form Tools

Unfortunately I don't think you'll be then able to attach the file to the email as an attachment... which leads us to your #2. Tricky!

Hmm.

How high a volume of form submissions are you expecting? One hack would be to always create the file with a specific filename, e.g. "myfile.pdf", and be sure to delete it when creating a new one. Then in your email template, always reference that specific filename by including it as an attachment.

Not great....

- Ben


RE: Saving binary file to database - nomad - Aug 23rd, 2009

Hi, Ben,
thank you for your message. My idea was straight (and naive) it is time to start respecting the reality :-))

Let me summarize my final way: "How to send a personalized email attachment".
Maybe can be useful to somebody, not great, but works, any improvements are welcomed.

1/ Use Pre-Parsel module to generate your attachment (an invoice in my case).

2/ Save the file to disc, the is no way how to save it to database.

3/ You have to use general name of the file, e.g. "Invoice.pdf" not unique one, as {$attachment} command does not accept placeholder to specify the name of the attachment.

4/ If no attachment should be generated for the current form, delete older file from disc (if exists).

5/ Use placeholders to personalize your message you like, e.g.:

{if $ANSWER_send_attachment == "Yes"}
Please find enclosed invoice.
{/if}

6/ Use direct command {$attachment file="invoice.pdf"} to send the attachment.
You cannot use any "if statements" as file attachments won't work within other Smarty logic. If no file "invoice.pdf" exists, no attachment is sent, no error message.

----

Pretty dirty white men's trick, uh?

This works, but not tested in real yet, theoretically, I am afraid if I receive two or more form applications at the very same time, one could delete prepared saved file attachment BEFORE this can be emailed by other process.

Please, Ben, if you find some extra time, add using placeholders in "$attachment file" command. Using unique names of attachments will make this process much less complicated.


RE: Saving binary file to database - Ben - Aug 24th, 2009

Hey, not bad at all! Yes, it's a hack - but good thinking with the Pre-Parser module. I should have thought of that...!

And yes, I hope to work on this at some point - but not soon, I'll be frank. Lots of other stuff to get done first!


RE: Saving binary file to database - SantiagoCHile - Sep 27th, 2013

(Aug 23rd, 2009, 11:03 PM)nomad Wrote: Hi, Ben,
thank you for your message. My idea was straight (and naive) it is time to start respecting the reality :-))

Let me summarize my final way: "How to send a personalized email attachment".
Maybe can be useful to somebody, not great, but works, any improvements are welcomed.

1/ Use Pre-Parsel module to generate your attachment (an invoice in my case).

2/ Save the file to disc, the is no way how to save it to database.

3/ You have to use general name of the file, e.g. "Invoice.pdf" not unique one, as {$attachment} command does not accept placeholder to specify the name of the attachment.

4/ If no attachment should be generated for the current form, delete older file from disc (if exists).

5/ Use placeholders to personalize your message you like, e.g.:

{if $ANSWER_send_attachment == "Yes"}
Please find enclosed invoice.
{/if}

6/ Use direct command {$attachment file="invoice.pdf"} to send the attachment.
You cannot use any "if statements" as file attachments won't work within other Smarty logic. If no file "invoice.pdf" exists, no attachment is sent, no error message.

----

Pretty dirty white men's trick, uh?

This works, but not tested in real yet, theoretically, I am afraid if I receive two or more form applications at the very same time, one could delete prepared saved file attachment BEFORE this can be emailed by other process.

Please, Ben, if you find some extra time, add using placeholders in "$attachment file" command. Using unique names of attachments will make this process much less complicated.

Hey dude! We use Fetchflow for online invoicing. Its completely free and as good as other paid solutions we tested. Has quite some traction. & I would actually recommend it.

http://www.fetchflow.com/support/question/How-do-I-schedule-recurring-invoices.html