Forums

Working with array data for multi upload element

bon-ja-mon 02 Mar, 2015
Hi

What an excellent product, many thanks.

I have a form that users can upload attachments using the multi upload element. I have this set up fine so the attachments are uploaded correctly and the file names are stored in an array in the database.

I have an issue, however, with working with this information on a subsequent form I am using for displaying the data to a different user. I can pull through the record data I require to the new form, except for the array with the attachments. I am trying to show a list of links to the uploaded files so the user can click them to see the attachments/download the attachments. I guess I need to use a Custom Element to loop through the array, but I am struggling with the code to do this.

Along the same vein, on the original submission form if the original user wanted to edit their submission this is straightforward for my normal fields such as text boxes, but I dont know how to show the user the content of the multi upload element so the user could either remove the attachments, change them or add to them like they could at the original form submission.

Can anyone help?
GreyHead 03 Mar, 2015
Hi bon-ja-mon,

This gets tricky in places because you can't edit uploaded files in the same way as text inputs etc. Please see this FAQ to start with - it deals with a single file upload but the same methods can be extended to more than one.

Bob
bon-ja-mon 03 Mar, 2015
Many thanks for the reply Bob, it is as I feared going to have to be a bit of coding to work with the uploaded files.

If I do this via a Custom Element I could loop through the array and then do something such as present a list of URLs on the site? Could you give me some example code as to how to loop through the array in a Custom Element (or before it was exploded when it was concatenated with comma delimiters if that is easier)?

Kind regards
GreyHead 03 Mar, 2015
Hi bon-ja-mon,

If you've got the comma separated version you can do something like this:
<?php
$files = explode(',', $form->data['links']);
$path = JUri::root().'some/path/to/files/folder/';
foreach ( $files as $f ) {
  echo "<div><a href='{$path}{$f}' >{$f}</a></div>";
}
?>

Bob
bon-ja-mon 04 Mar, 2015
Excellent Bob, many thanks.

It was the explode line that I hadn't figured out, and I think I can fumble my way to getting my desired results.

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