2
votes

Friends,

I'm trying to get the File Upload form field to work on Joomla 2.5(.11). For some reason I can't get the file to upload.

As soon as I click "Save", the file upload field says "No file chosen", again.

I've searched the docs and discussions to no avail. I did find information on how to do a file upload on a backend component -- leveraging PHP, of course.

I've attached my XML file code (but removed the personally identifying information and such).

I really appreciate any help with this that's different from the other posts on Stack which focus on the PHP solution -- I'm looking to do this using the module params.

http://docs.joomla.org/File_form_field_type

<?xml version="1.0" encoding="utf-8"?>
<extension
        type="module"
        version="2.5"
        client="site"
        method="upgrade">
    <version>2.5.0</version>
    <config>
        <fields name="params" >
            <fieldset name="basic">
                <field name="file1" type="file" label="Upload" description="Upload a file" size="10" />
            </fieldset>
        </fields>
    </config>
</extension>

It says in the docs to use enctype="multipart/form-data" in the form field, however I'm not sure where that would go here... I tried wrapping the fields in a form field and using that, I also tried setting it to the config and fields elements to no avail.

Any help is greatly appreciated, thanks friends.

2
I'm not sure that you can get this to work. Whenever I use this in a component, I have to add the upload processing myself. I don't think it will work without it. What are you trying to do with this file? You may be able to get by with the Media field type instead if the file is an image.David Fritsch
The files would most likely be pdf/xml/doc. From what I understand most people do the upload processing manually; I just feel that since there is a module parameter for this the Joomla devs may have written it in...(or it's a wild goose chase)Jaime

2 Answers

1
votes

I recently came across the same problem, uploading a file from the back-end of a component / module.

From what I found I can tell you that:

  • using the type file just generates the html, but not the functionality.
  • The type media you can upload files, generally images and co. I had no success with pdf/xml/doc (especially getting the media manager to display them, so that I can select one- there is a view that shows only media files). For some documents types, you need to configure some security checks to allow the upload of this files.
  • Type fildlist generates a dropdown with available files, so you can select one.

Possible solution (I did not try it, but rethinking what I have tried, it may work). 1 Upload the file with media. 2. Refresh page by saving. 3. Select file from dropdown.

Let me know if this helps.

1
votes

If you have a supporting component and tables class, you can easily use the file field type to handle all the front end HTML and overload the store method in the JTable class. Insert the following lines of code:

        $src = $form['jform']["tmp_name"]['document'];
    $path = JPATH_ROOT . "/media/com_mycomponent/documents/";
    $name = $form['jform']['name']['document'];
    $this->document = $name;
    JFile::upload($src, $path . $name);

This code snippet assumes the field name is document and you wish to store where ever path points to. That will help you save the actual file, however; you will need to add logic to the table or model class to flag and alter the form to reflect a file is indeed uploaded but still provide an option to change if needed.

Anyone got some suggestions for that lol?