Search code examples
phpjoomla

how to upload multiple image in my backend module joomla form


I am developing a module in Joomla 3.x and want to add a browse button on the backend so the user can pick a file they have previously uploaded but when I use a media type in the mod_module_name.xml I can upload only one picture.

I use the code below in a xml file but I can upload only one picture? How would I go about this?

               <field
                    name="image_intro"
                    type="media"
                    label="Select an Image"
                    description=""
                    class="inputbox" />

Solution

  • When uploading, you can upload multiple images at the same time. When you click "Browse", you can select multiple images to be uploaded by holding CTRL on the keyboard and selecting your chosen images.

    Update

    The above only applies when uploading. If you are referring to selecting an image, what I would recommend doing is allowing the user to type in the directory of where the images have been uploaded to. Then in your module, you get the directory value and get all the images from there.

    So in your XML file, use the following:

    <field
        name="directory"
        type="text"
        default="images/yourfolder"
        label="Type in your image directory"
        description=""
        class="inputbox" />
    

    Then assuming the user has typed in images/customfolder, you can use the following which will display all images from that folder:

    <?php 
        $directory = $params->get('directory');
        $path = JPATH_SITE . '/' . $directory;
        $exclude = array('index.html');
        $images = JFolder::files($path, '.', null, null, $exclude );
    
        foreach($images as $image)
        {
            echo '<img src="' . JUri::root() . $directory . '/' . $image . '" alt="" />';
        }
    ?>
    

    As you can see, I have excluded the index.html and you can add more excludes to the array.

    The user will of course be expected to upload the images using Joomla's Media Manager.