Forums

Listing uploaded files in an email

MarkRS 28 May, 2015
I've written a form to allow people to upload (a variable number of) files.
On submission it uploads the files and emails the uploader and the administrator with a short thank-you message with a list of the files uploaded. All good so far.

What I can't find a way to do is to list the file names that were uploaded, as opposed to the names they were saved as.

I've taken my cue from the file upload demo to add the datetime to the filenames, great idea, but I'd rather not put that name in the email.

With a debugger I can see the original name is available, but I just can't seem to get it into the email. I've scoured the forums here and banged my head on the desk, a lot, but I still can't figure out how to do it. Is there a way?
MarkRS 28 May, 2015
Thanks Prof, but I think your circuits probably need recharging, you've missed the point a little 😃
MarkRS 28 May, 2015
D*mn! No edit function.

I meant "your circuits", obviously 😲
GreyHead 28 May, 2015
Hi MarkRS,

Please excuse the Prof - he tries hard . . .

Please post your debugger output here.

Bob
MarkRS 28 May, 2015
Hi Bob,

Here's the (double) debugger output [attachment=0]Screen Shot 2015-05-28 at 14.21.55.jpg[/attachment] and also the setup that generated it [attachment=1]Screen Shot 2015-05-28 at 14.23.34.png[/attachment].

Don't worry about the smtp failure, this is just my local machine, it works fine hosted.
Yes, two debugger entries, desperation an' all that.

"1, 2 & 3" refer to three different strategies I've got in the email action. They are

{file_upload} 1

{ofn} 2

{repeat:file_upload}
{original_name}
{/repeat}
3

I also tried a fourth

{repeat:files}
{name} - {original_name}
{/repeat}

which (also) produced nothing.
Many of the FAQs have no (real) publication date on them, so it can be hard to know if they're for the current version. The search function (which now seems to work, great!) doesn't show a breadcrumb trail so I can't tell where they're from either.

Sorry for the long post.
GreyHead 28 May, 2015
Hi Mark,

Please try this.

Add a Custom Code action in the On Submit event and move it up after the Upload Files action and before the Email action. Add this code:
<?php
$file_names = array();
foreach ( $form->files['file_upload'] as $f ) {
  $file_names[] = $f['original_name'];
}
$form->data['file_names'] = implode(', ', $file_names);
?>
Then add {file_names} to the Email template.

Bob
MarkRS 28 May, 2015
Thanks Bob,

I thought I'd tried that, but clearly I hadn't.

I think it's a confusion on my part on what the debugger output shows, for example it doesn't show the $form->files array, though it is there.

Secondly, is there something I can put in a string that will give me a carriage return? I tried <br /> and <br> but they just printed as text.
GreyHead 28 May, 2015
Answer
1 Likes
Hi Mark,

You are right, the debug output doesn't tell you where the data is. The form data is in the $form->data array and the files data in $form->files.

If you ever need to know then adding a Custom Code action with
<?php
echo'<div>$form: '.print_r($form, true).'</div>';
?>
will dump the lot - expect to spend some time in the page source finding exactly what you need.

Where do you want the line-break? In the files list you can try implode("\n", . . .)

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