Forums

Store file upload path and filename in SQL

shifty_ 28 May, 2014
Hi There, I have searched the forums and found a lot of helpful information in setting this up - and so far I have the following that is working great:

A form with 3 File upload fields that successfully upload the files to a custom folder and it also stores the filenames (e.g. 20140528100148__DSC0194.jpg) in SQL.

But I can't figure out how to append the path name (e.g. http://www.sample.com/images/uploads/) to the file name so that when i run the Excel export and download the .xls file that it has a nice link in the spreadsheet columns that you can click on. E.g:

http://www.sample.com/images/uploads/20140528100148__DSC0194.jpg

At the moment, it just has the filename only in the spreadsheet. E.g. "20140528100148__DSC0194.jpg".

Thanks!
GreyHead 28 May, 2014
Hi shifty,

you can do that by adding a Custom Code action between the Upload Files action and the DB Save action to edit the file name to include the link. Or, better, as the link is already in the $form->data array then copy that value over the file_name.

Bob
shifty_ 28 May, 2014
Thanks GreyHead - I will give it a go... Not sure if you can update the FAQs section - but you probably know who can... This page in the FAQs:

http://www.chronoengine.com/faqs/63-cfv4/cfv4-working-with-form-data/2697-how-can-i-use-the-form-data.html

It needs the link to the FAQ "How can I use the form data with PHP" updated. The correct URL to that FAQ is:

http://www.chronoengine.com/faqs/63-cfv4/cfv4-working-with-form-data/2594-how-can-i-use-the-form-data-with-php.html
GreyHead 29 May, 2014
Hi _shifty,

Thanks for pointing out the broken link - it's fixed now.

Bob
marverance 01 Jul, 2014

Hi shifty,

you can do that by adding a Custom Code action between the Upload Files action and the DB Save action to edit the file name to include the link. Or, better, as the link is already in the $form->data array then copy that value over the file_name.

Bob


Please what is the code i can put in the "custom code action" Thanks for your quick responses. and your support.
Max_admin 01 Jul, 2014
Assuming the database field name which is going to include the file path is named "path" then you can use this code:

<?php
$form->data["path"] = $form->files["file_field_name"]["path"]; // replace the file_field_name
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
marverance 25 Jul, 2014
Thank you sir for this reply. but, after puting it this way <?php
$form->data["upload_photo"] = $form->files["file_field_name"]["upload_photo"]; // replace the file_field_name but after that, the file path does not show on the upload_photo field. i did every thing you said.
Max_admin 27 Jul, 2014
The code is added into a "custom code" action which is AFTER the "upload files" ?

And the "DB Save" is AFTER both ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
marverance 27 Jul, 2014
Yes Sir the DB is after both
Max_admin 28 Jul, 2014
Ok, after the "custom code" and before the "db save" please add a debugger action and post the output!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
marverance 02 Aug, 2014
Array
(
    [option] => com_chronoforms
    [chronoform] => ICLC_REG_SPECIAL
    [event] => submit
    [Itemid] => 
    [full_name] => marvel
    [gender] => Male
    [church] => Ce Ozoro
    [cell] => blaze
    [leader_position] => Senior Cell Leader
    [date_of_birth] => 2014-08-15
    [phone_num] => 08065724699
    [email] => marverance4peace@yahoo.com
    [yookos_id] => kudos
    [Submit] => Submit
    [e7aa58696a1dae59ada1637afe393a5e] => 1
    [file_upload] => 
    [_PLUGINS_] => Array
        (
            [upload_files] => Array
                (
                    [file_upload] => Array
                        (
                            [name] => 20140801212133_102.JPG
                            [original_name] => 102.JPG
                            [path] => /home/christem/public_html/reg/components/com_chronoforms/uploads/ICLC_REG_SPECIAL/20140801212133_102.JPG
                            [size] => 688985
                            [link] => http://reg.christembassyughelli.org/components/com_chronoforms/uploads/ICLC_REG_SPECIAL/20140801212133_102.JPG
                        )

                )

        )

)
Validation Errors: 
Array
(
)
Debug Data
Upload routine started for file upload by : file_upload
/home/christem/public_html/reg/components/com_chronoforms/uploads/ICLC_REG_SPECIAL/20140801212133_102.JPG has been uploaded successfully.
GreyHead 02 Aug, 2014
Hi shifty_.

Please see this FAQ that shows you where the link is saved. You can use that to build a link in a custom code action after the Upload Files action and before the DB Save action.
<?php
$temp = $form->data['_PLUGINS_']['upload_files']['input_file_1']['link'];
$temp = "<a href='{$temp}'>{$form->data['input_file_1']}</a>";
$form->data['file_link'] = $temp;
?>
Note: not tested and may need debugging!

Replace input_file_1 with the name of your file input and file_link with the database column name.

Bob
marverance 07 Aug, 2014
Thanks alot. it worked. but it is not click able. on the show data and on excel sheet <a href='http://reg.christembassyughelli.org/components/com_chronoforms/uploads/ICLC_REG_SPECIAL/20140807183521_432039_385404221487369_216581293_n.jpg'>20140807183521_432039_385404221487369_216581293_n.jpg</a>
marverance 07 Aug, 2014
Also, i want to know how to submit a form to different tables base on a field criteria. that is, Mr A,B,C and D are members of my website. and i want report from them each day. i want their reports to be submitted on different tables that i created for them. so, their user name will be the criteria.. thanks alot i appreciate your quick response
GreyHead 09 Aug, 2014
Hi marverance,

I don't think that you can dynamically set a table name in any of the ChronoForms actions so you'd need to use a Custom Code action and write your own mySQL query to do that.

But. . . why are you using separate tables? It's better design to use one table and add a membername or, better, user_id column to it.

Bob
marverance 09 Aug, 2014
the report from user A, B, C, D will be submited to four head of departments. report from user A will be submitted to department 1. User B report to department 2. Report from user C will be submited to department 3. and so on. if i use the same table, all the HOD will see each others reports. please if it is a code i will have to use, please help me with the template code. thanks alot.😀
Max_admin 13 Aug, 2014
In this case you may build a form and use the "Export CSV" action, drag a "DB Multi record loader" before it to load the data you need for a specific HOD, you can control this using some data parameter, and that would generate a report with records for that HOD only, each record in the table must have a HOD identifier though, like a new field named "hod" with fields like a, b, c or d

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
marverance 13 Aug, 2014
Thanks sir. but i need each of the HOD to login to the site, and see the forms that were submitted for him. and will not be able to see the forms submitted for the other HODs
Max_admin 14 Aug, 2014
This is also possible if you have a field in the table to associate the records to different HODs
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.