Linking an uploaded file

How to create a clickable link to an uploaded file in a ChronoForms email.

Overview

The issue occurs because the curly-bracket placeholder method for file links does not work in CFv5, and the upload action incorrectly returns a server path instead of a web URL.
Use a PHP snippet in the email body to output the correct link, and add a custom code action after the upload to convert the server path to a full web URL.

Answered
MS MSGraphics 25 Jul, 2014
So I'm having trouble with linking a file thats been uploaded to an email.

what I have in the "Email" action is this:

<table>
<tbody>
<tr>
<td>You are a ...</td>
<td>{dropdown7}</td>
</tr>
<tr>
<td>This is an ...</td>
<td>{dropdown8}</td>
</tr>
<tr>
<td>Array</td>
<td>{text1}</td>
</tr>
<tr>
<td>Array</td>
<td>{text2}</td>
</tr>
<tr>
<td>Array</td>
<td>{text3}</td>
</tr>
<tr>
<td>Array</td>
<td>{text4}</td>
</tr>
<tr>
<td>Tell Us About Your Prjoect</td>
<td>{textarea6}</td>
</tr>
<tr>
<td>Upload your Artwork</td>
<td><a href="{_PLUGINS_.upload_files.file5.link}">{_PLUGINS_.upload_files.file5.name}</a></td>
</tr>
</tbody>
</table>


and the Debug comes out like this:

Data Array
Array
(
    [option] => com_chronoforms5
    [chronoform] => FileUpload2
    [event] => submit
    [dropdown7] => NewCustomer
    [dropdown8] => Estimate
    [text1] => Ricardo
    [text2] => Contreras
    [text3] => ricardoacontreras@gmail.com
    [text4] => 
    [textarea6] => 
    [button9] => Submit
    [file5] => 20140725170532_cut_door_vinyl.ai
    [ip_address] => 71.179.234.105
)
Array
(
    [file5] => Array
        (
            [name] => 20140725170532_cut_door_vinyl.ai
            [original_name] => cut_door_vinyl.ai
            [path] => /home6/mdsignsg/public_html/components/com_chronoforms5/chronoforms/uploads/FileUpload2/20140725170532_cut_door_vinyl.ai
            [size] => 1123463
            [link] => /home6/mdsignsg/public_html/components/com_chronoforms5/chronoforms/uploads/FileUpload2/20140725170532_cut_door_vinyl.ai
        )

)
Errors
Array
(
)
Debug Info
Array
(
    [9] => Array
        (
            [Files Upload] => Array
                (
                    [0] => Upload routine started for file upload by : file5
                    [1] => /home6/mdsignsg/public_html/components/com_chronoforms5/chronoforms/uploads/FileUpload2/20140725170532_cut_door_vinyl.ai has been uploaded successfully.
                )

        )

    [0] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:msg@marylandsignsandgraphics.com
                    [2] => Subject:
                    [3] => From name:Ricardo
                    [4] => From email:ricardoacontreras@gmail.com
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Body:
<table>
<tbody>
<tr>
<td>You are a ...</td>
<td>NewCustomer</td>
</tr>
<tr>
<td>This is an ...</td>
<td>Estimate</td>
</tr>
<tr>
<td>Array</td>
<td>Ricardo</td>
</tr>
<tr>
<td>Array</td>
<td>Contreras</td>
</tr>
<tr>
<td>Array</td>
<td>ricardoacontreras@gmail.com</td>
</tr>
<tr>
<td>Array</td>
<td></td>
</tr>
<tr>
<td>Tell Us About Your Prjoect</td>
<td></td>
</tr>
<tr>
<td>Upload your Artwork</td>
<td>20140725170532_cut_door_vinyl.ai</td>
</tr>
</tbody>
</table>

<a href="">20140725170532_cut_door_vinyl.ai</a><br /><br />IP: 71.179.234.105
                )

        )

)


Where did I go wrong?
Gr GreyHead 27 Jul, 2014
Answer
1 Likes
HI MSGraphics,

It looks to me as though the way the data is saved in CFV5 has changed a bit and the curly-brackets method will not longer work for the file URL.

Please try this instead:
<tr>
<td>Your Artwork</td>
<td><a href='<?php echo $form->files['file5']['link']; ?>' >{file5}</a></td>
</tr>

Bob
MS MSGraphics 31 Jul, 2014
That seems to have worked to get the link in there, but now I'm having an issue where the link doesn't seem to be complete :<br /><br /><pre class="ui message cfu-code" style="overflow:auto; border:none;">Data Array<br />Array<br />(<br /> [option] => com_chronoforms5<br /> [chronoform] => FileUpload2<br /> [event] => submit<br /> [dropdown7] => NewCustomer<br /> [dropdown8] => Estimate<br /> [text1] => xxx<br /> [text2] => xxx<br /> [text3] => xxx<br /> [text4] => +1(561)267-7614<br /> [textarea6] => THE FINAL COUNTDOWN<br /> [captcha] => <br /> [button9] => Submit<br /> [file5] => 20140731131450_cut_door_vinyl2.ai<br /> [ip_address] => Xxx<br />)<br />Array<br />(<br /> [file5] => Array<br /> (<br /> [name] => 20140731131450_cut_door_vinyl2.ai<br /> [original_name] => cut_door_vinyl2.ai<br /> [path] => /home6/mdsignsg/public_html/components/com_chronoforms5/chronoforms/uploads/FileUpload2/20140731131450_cut_door_vinyl2.ai<br /> [size] => 1133566<br /> [link] => /home6/mdsignsg/public_html/components/com_chronoforms5/chronoforms/uploads/FileUpload2/20140731131450_cut_door_vinyl2.ai<br /> )<br /><br />)<br />Errors<br />Array<br />(<br />)<br />Debug Info<br />Array<br />(<br /> [9] => Array<br /> (<br /> [Files Upload] => Array<br /> (<br /> [0] => Upload routine started for file upload by : file5<br /> [1] => /home6/mdsignsg/public_html/components/com_chronoforms5/chronoforms/uploads/FileUpload2/20140731131450_cut_door_vinyl2.ai has been uploaded successfully.<br /> )<br /><br /> )<br /><br /> [0] => Array<br /> (<br /> [Email] => Array<br /> (<br /> [0] => An email with the details below was sent successfully:<br /> [1] => To:msg@xxx.com<br /> [2] => Subject:New File/Estimate Request<br /> [3] => From name:Ricardo<br /> [4] => From email:ricardoacontreras@gmail.com<br /> [5] => CC:<br /> [6] => BCC:<br /> [7] => Reply name:<br /> [8] => Reply email:<br /> [9] => Attachments:<br /> [10] => Body:<br /><table><br /><tbody><br /><tr><br /><td>You are a ...</td><br /><td>NewCustomer</td><br /></tr><br /><tr><br /><td>This is an ...</td><br /><td>Estimate</td><br /></tr><br /><tr><br /><td>Array</td><br /><td>Xxx</td><br /></tr><br /><tr><br /><td>Array</td><br /><td>Xxx</td><br /></tr><br /><tr><br /><td>Array</td><br /><td>Xxx@gmail.com</td><br /></tr><br /><tr><br /><td>Array</td><br /><td>+1(561)267-7614</td><br /></tr><br /><tr><br /><td>Tell Us About Your Prjoect</td><br /><td>THE FINAL COUNTDOWN</td><br /></tr><br /><tr><br /><td>Your Artwork</td><br /><td><a href='/home6/mdsignsg/public_html/components/com_chronoforms5/chronoforms/uploads/FileUpload2/20140731131450_cut_door_vinyl2.ai' >20140731131450_cut_door_vinyl2.ai</a></td><br /></tr><br /></tbody><br /></table><br /><br />IP: 71.179.234.105<br /> )<br /><br /> )<br /><br />)</pre><br /><br />Is there a way to change how the Upload action makes the "link"?
Gr GreyHead 01 Aug, 2014
1 Likes
Hi MSGraphics,

This looks like a bug in the CF code - the Upload Files action is returning a path in the [link] variable :-(

I had quick look at the code and that looks OK so there may be something I missed, or an odd combination of data that causes it to fail.

As a temporary fix please try adding this to a Custom Code action after the Upload Files action and before the Email action.
<?php
foreach ( $form->files as $k => $f ) {
  if ( $f['path'] == $f['link'] ) {
    $form->files[$k]['link'] = str_replace(JPATH_SITE.DS, JURI::root(), $f['link']);
  }
}
?>
Notes:
+ Not tested and may need debugging!
+ This is Joomla! only

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