Buy Now
Sign in

Chronoforms 6 - Filepath and link for file upload

4Summit , July 06 2017
4
4Summit
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.
4
4Summit
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).
admin
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
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
momentis
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
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
D
Denny87
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 ->&nbsp;[file21] => mydocument.pdf
The name of the file on my server gets a timestamp like:&nbsp;20180712072529_mydocument.pdf
I want to link in my email to my uploaded file like:&nbsp;https:/www.mydomain.de/path/20180712072529_mydocument.pdf
Do you know how i can realize it?
Thanks,
Denny
H
healyhatman
<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.
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
D
Denny87
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.
H
healyhatman
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.
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
D
Denny87
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}"​
​​
H
healyhatman
The read data where clause should look exactly like the one in your verify event
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
D
Denny87
I changed, thanks, i think there is something wrong with the link.​
​It only looks like this:​
​"..................&event=download&vid="
H
healyhatman
Well you will need to generate a new key obviously and save THAT key to the database after verification
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
D
Denny87
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?
H
healyhatman
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.
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
H
healyhatman
Why not just attach the file to the email?
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
D
Denny87
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?
H
healyhatman
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
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
D
Denny87
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?
H
healyhatman
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.
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman