Forums

Chronoforms 6 - Filepath and link for file upload

4Summit 06 Jul, 2017
Hello,

I am trying to create a simple page for file uploads and store the path and link in the database, I enabled the debugger and the output is below.

Array
(
    [upload15] => Array
        (
            [path] => C:\wamp64\www\Joomla\components\com_chronoforms6\chronoforms\uploads\
            [file1] => Array
                (
                    [extensions] => Array
                        (
                            [0] => jpg
                            [1] => png
                            [2] => gif
                            [3] => pdf
                            [4] => doc
                            [5] => docx
                            [6] => txt
                            [7] => zip
                        )

                    [saved] => 1
                )

            [var] => Array
                (
                    [file1] => Array
                        (
                            [path] => C:\wamp64\www\Joomla\components\com_chronoforms6\chronoforms\uploads170706020936_011-new.jpg
                            [filename] => 20170706020936_011-new.jpg
                            [name] => 011_new.jpg
                            [size] => 367426
                        )

                )

        )

)

1) How do I access the path? My custom code is not working.
$form->data['path'] = $form->data['upload15']['var']['file1']['path'];

2) How can I get access to the link? I would like to show the link for downloads.
4Summit 07 Jul, 2017
1 Likes
Solution for quesiton #1 (in case others are looking for the same).

<?php
$path = $this->get("upload15.file1.path","path not found");
$filename = $this->get("upload15.file1.filename","filename not found");
$name = $this->get("upload15.file1.name","name not found");
$size = $this->get("upload15.file1.size",0);
$this->data("path",$path,true);
$this->data("filename",$filename,true);
$this->data("name",$name,true);
$this->data("size",$size,true);
?>

Can someone please help with how to get a link for the uploaded documents? It appears CF v6 does not have it (perhaps i missed it).
Max_admin 14 Jul, 2017
Hi 4Summit,

You can get the info you need in the email or in the database using the shortcodes, just use {var:upload15.file1.name}

To get a link to the file just use http://domain.com/path/{var:upload15.file1.filename}

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
momentis 10 Apr, 2018
Max,

New to this version! I cannot figure out how to use the shortcode you mention above to save the filename to the database for a form I am building. How is that code implemented to save the filename to a field in the table?

Rick
momentis 10 Apr, 2018
I figured it out. I need to use the shortcode in my Save Data action, in the "Data override on insert" section, tied to the fieldname.

Sorry!
Rick
nbushuven@gedak.de 12 Jul, 2018
Hi Max,

i want to link to a uploaded file as well and tried the shortcode but it doesn't work in my case. (CF6)

For your understanding:
User is filling the form and uploads a file.

SUBMIT EVENT
Everything is saved in db.
User gets an email with verification link to verify his email.

VERIFY EVENT
After verification i'm getting an email and it shows all informations of the last modified data record (verified=1)
It shows as well the filename of the uploaded file -> [file21] => mydocument.pdf

The name of the file on my server gets a timestamp like: 20180712072529_mydocument.pdf

I want to link in my email to my uploaded file like: https:/www.mydomain.de/path/20180712072529_mydocument.pdf

Do you know how i can realize it?

Thanks,
Denny
Denny87 12 Jul, 2018
Hi Max,

i want to link to a uploaded file as well and tried the shortcode but it doesn't work in my case. (CF6)

For your understanding:
User is filling the form and uploads a file.

SUBMIT EVENT
Everything is saved in db.User gets an email with verification link to verify his email.

VERIFY EVENT
After verification i'm getting an email and it shows all informations of the last modified data record (verified=1).
It shows as well the filename of the uploaded file -> [file21] => mydocument.pdf

The name of the file on my server gets a timestamp like: 20180712072529_mydocument.pdf
I want to link in my email to my uploaded file like: https:/www.mydomain.de/path/20180712072529_mydocument.pdf

Do you know how i can realize it?

Thanks,
Denny
healyhatman 12 Jul, 2018
<a href = "https://www.mydomain.de/{var:fileuploadname.path}"  download="customfilename.pdf">Download the pdf</a>
Be aware doing it the way you're asking means that anyone can download anyone else's document. Much better to have a download link that includes the verification code and points to another event with a Download action.

Also

After verification i'm getting an email and it shows all informations of the last modified data record (verified=1).


NO. NO NO NO. What happens if someone else modifies a record in between submission and verification? You're handing someone's data over to random people.
Denny87 12 Jul, 2018
Thanks, healyhatman
You know how my verification is working because you helped me a lot to realize it.

I just want to create the link with filename that im able to download the file. The folder where i save the files is blocked for external.
healyhatman 12 Jul, 2018
Then you need to do what I said. You can't use the the filename here's what you do instead.

In your email you need the link to be
<a href = "https://mysite.com/index.php?option=com_chronoforms6&chronoform=form_name&event=download&verification={var:verificationcode}">Download PDF</a>
replace {var:verificationcode} with the right thing of course.

The event you have called "download" you need to have a read data action that retrieves the record where you've stored the file path (where the verification code matches, just like the verify link)
Then you need a Download action: file or directory path should be {var:read_data.model.filepath} or if you've only stored the file name it should be {path:root}/path/{var:read_data.model.filename}

Doing it this way means that you can keep the directory locked down and people will need the verification code in the link to be able to download the file.
Denny87 12 Jul, 2018
Thanks,

i'm not sure if i did understand everything correctly.

My verification link in my submit event looks like: ".......&event=verify&vid={var:verification_id}"
-> works

After submitting the link, update db from vid=0 (not verified) to vid=1 (verified) + send mail to me to get all informations like name etc.
-> works

Now i have created a new event "download"
Actions: read data (how should the 'where conditions' look like?)
-> FOUND -> download action -> {path:root}path/{var:read_data36.data36.filename}

I put the link in my verify email:
".......&event=download&vid={var:verification_id}"

healyhatman 12 Jul, 2018
The read data where clause should look exactly like the one in your verify event
Denny87 12 Jul, 2018
I changed, thanks, i think there is something wrong with the link.
It only looks like this:
"..................&event=download&vid="
healyhatman 12 Jul, 2018
Well you will need to generate a new key obviously and save THAT key to the database after verification
Denny87 12 Jul, 2018
Why should i have to generate a new one? I have saved the key and changed the vid from 0 to 1.
Can't i just check if this condition is given?
healyhatman 12 Jul, 2018
For the reasons I said before. There needs to be a verification step and code for two reasons : so you know which record to select, and so users can't just download whatever files they want.
healyhatman 12 Jul, 2018
Why not just attach the file to the email?
Denny87 12 Jul, 2018
Attaching the file works in my submit email.
But how can i attach the file in my email action in my verify event after the user had verified his email?
healyhatman 12 Jul, 2018
the same way? I don't understand. If you're in the verify event you have the row that should contain your file path so you should be able to attach that file
Denny87 12 Jul, 2018
When i use my email action in my submit event and use "Auto Attach file fields" it works perfectly and the uploaded file is attached to the mail.

In my verify event i update my db (setting vid from 0 to 1), check it with a read data and then i send an email to me.
In this mail i need the uploaded file. But there is no file attached when i use "Auto Attach file fields".
Should i write something in "Attachments list", if so, what should i have to do?
healyhatman 12 Jul, 2018
Of course Auto attach won't work you haven't uploaded anything within the event.

You said you saved the filename to the database. That's what you need to put in the file field to attach.
Denny87 13 Jul, 2018
Can you tell me what to put in the attachments list?
Tried the full path: {path:root}/path/{var:read_data36.file21.filename} but this causes only that the mail is not send.
healyhatman 13 Jul, 2018
You didn't literally just put that did you? You replaced that middle "/path/" with the correct path to your file right? And have you ACTUALLY got the filename by using the {var:read_data} you've put there?

USE A DEBUG ACTION
Denny87 13 Jul, 2018
Of course i replaced "/path/".

What do you mean by ""And have you ACTUALLY got the filename by using the {var:read_data} you've put there?.
I can see in my email with {var.pr:read_data36} the filename in [file21] => documentname.pdf
Debugger: [result] => the Mail could not be sent.
healyhatman 13 Jul, 2018
So does the filename that gets returned to you actually exist in the right place on the server?
Denny87 13 Jul, 2018
No, because there is a timestamp before the original filename. Thats what i asked at the beginning of my question how to get this filename with the timestamp.
Example: 20180713062638_documentname.pdf
healyhatman 13 Jul, 2018
You've saved the wrong thing to the database, you need the filename from the upload action var not the filename from {data:upload_field}
Denny87 13 Jul, 2018
Can you give me an example? I don't know what to do.
healyhatman 13 Jul, 2018
You need to save {var:file_upload_action.file_field.filename} to the database, not .name or {data:file_field} or whatever you're saving now,

For example
{var:upload35.file27.filename}
Denny87 13 Jul, 2018
This filename is saved automatically, i did not save the file name by my own.
I changed it now and i can see in my debugger and db that in [file21] the full filename is saved (with timestamp).
Now i put this line in my attachments list in my email after the user has verified, but the mail still could not be send.
{path:root}/path/{var:read_data33.file21.filename}
healyhatman 13 Jul, 2018
Are you sure your read data action's MODEL name is "file21" ?
Denny87 13 Jul, 2018
No, thats why i'm asking what to do.

The action name is read_data33, the model name Data33
and in file21 should be the filename.

So how should the line look like?
healyhatman 13 Jul, 2018
Come on mate are you serious? You wouldn't be having so much trouble if you read the instructions.
{var:read_data33.Data33.file21}
Denny87 13 Jul, 2018
You really think that i'm stupid, but thats what i tried several times and it is still not working!
[result] => the Mail could not be sent.
healyhatman 13 Jul, 2018
Works for me .

What does the REST of the debug action say? Like very importantly the part of the email action that says "files" ? Does it have the right path and filename there?
Denny87 13 Jul, 2018
*Changed the path:
            [files] => Array
                (
                    [0] => /srv/www/www.mydomain.de/www/folder1/folder2/
                )

            [result] => the Mail could not be sent.
            [var] => 

And the part of my model:
            [Data33] => Array
                (

                    [file21] => 20180713100447_mydocument.pdf

                )
healyhatman 13 Jul, 2018
OK so as you can see there, you've got the PATH but you don't have the FILENAME in the attachment.

So again it should be
{path:root}/folder/{var:read_data33.Data33.file21}
Denny87 13 Jul, 2018
So here you can see what i have and its still not working:

healyhatman 13 Jul, 2018
Did you copy paste that last shortcode from the forums? If you did, select all and delete it and type it out manually.
Denny87 13 Jul, 2018
Typed it out manually -> same result.
healyhatman 13 Jul, 2018
the read data action is in the same event right? If you paste that whole line in a custom code action, is the text of the correct path to the file?
Denny87 13 Jul, 2018
Yes the read data and email actions are in my verify event.

I'm just getting the path without the filename:
/srv/www/www.mydomain.de/www/folder1/folder2/
healyhatman 13 Jul, 2018
Can you please paste the WHOLE debug here instead of snippets?
Denny87 13 Jul, 2018




- a lot of email template code -

healyhatman 13 Jul, 2018
Ok so what you've done is you've got your read data set to retrieve all matching records. Change it to first matching.
Denny87 13 Jul, 2018
It works!
Thanks mate!
This topic is locked and no more replies can be posted.