简体   繁体   English

如何在我的后端模块joomla表单中上传多个图像

[英]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. 我正在Joomla 3.x中开发一个模块,并希望在后端添加一个浏览按钮,以便用户可以选择他们以前上传的文件,但是当我在mod_module_name.xml中使用媒体类型时,我只能上传一张图片。

I use the code below in a xml file but I can upload only one picture? 我在xml文件中使用以下代码,但是只能上传一张图片? How would I go about this? 我将如何处理?

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

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. 单击“浏览”时,可以通过按住键盘上的CTRL并选择所选的图像来选择要上载的多个图像。

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: 因此,在您的XML文件中,使用以下命令:

<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: 然后,假设用户输入了images/customfolder ,则可以使用以下命令显示该文件夹中的所有图像:

<?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. 如您所见,我已经排除了index.html,并且可以向该数组添加更多的排除项。

The user will of course be expected to upload the images using Joomla's Media Manager. 当然,期望用户使用Joomla的媒体管理器上传图像。

In Joomla 3.9.x use the File form field type and specify multiple=true. 在Joomla 3.9.x中,使用“文件”表单字段类型并指定“ multiple = true”。 See https://docs.joomla.org/File_form_field_type 参见https://docs.joomla.org/File_form_field_type

<field name="images"
   type="file"
   label="Select image(s) to upload"
   description="Choose one or more images from your computer"
   size="10"
   multiple="true"
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM