4

I am developing a component which has a front-end form. In this form it must be possible to select and upload a File to a user-specific directory.

I found and tested the module Easy File Uploader and it fits my requirements for uploading files (I am using the option "Upload to Username subfolders". The module will then create a folder for each user). The component only allows me to upload files, but not select them again. I placed the module in my edit-form of the component.

Now i have a directory like this:

  • Images
    • User1
      • File1
      • File2
      • File3
      • File4
      • ...
    • User2
      • File1
      • ...

Now i want to be able to select the files again. (So I can store the filepath for the profile image into the Database) I thought about using a simple dropdown, but how can I realize it with the mvc pattern of joomla 3.3?

EDIT:

Oh, im a bit blind, so I found the form field "filelist" on the joomla docs: http://docs.joomla.org/Filelist_form_field_type

Is there a way to set the directory in the code dynamically?

3
  • What have you tried to far? Have a look into Joomla's filesystem package, using JFolder and JFile
    – Lodder
    Aug 28, 2014 at 19:48
  • I think i won't have a problem with looping the folder, but how do I apply this data to the form-xml file?
    – Marc T.
    Aug 28, 2014 at 20:16
  • 1
    JForm can take a string as xml as well, so you can create an array structure from the data then convert to xml and pass it to JForm. Aug 28, 2014 at 21:38

1 Answer 1

4

In your model, after loading the form, you can use setFieldAttribute to set the directory dynamically like so:

$form->setFieldAttribute('myfile', 'directory', 'media/media/images');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.