使用 managed_file 以自定义形式上传多个文件

Multiple file upload in custom form with managed_file

我正在 Drupal 7 中构建一个带有图片上传字段的自定义设置表单。此图片字段应允许多次上传。

经过一些研究,我发现您可以使用 managed_file'#attributes' => array('multiple' => 'multiple') 来做到这一点。然而,这似乎没有任何作用。

这是我目前拥有的代码:

$form['frontpage_banner_images'] = array(
  '#type' => 'managed_file',
  '#title' => t('Frontpage Images'),
  '#name' => 'files[]',
  '#attributes' => array(
    'multiple' => 'multiple',
    'class' => 'testclass',
  ),
  '#upload_location' => 'public://homepage-banners/',
  '#default_value' => variable_get('frontpage_banner_images'),
);

结果是:

<div class="form-item form-type-managed-file form-item-files-">
  <label for="edit-frontpage-banner-images-upload">Frontpage Images</label>
  <div id="edit-frontpage-banner-images-upload" class="testclass form-managed-file">
    <input type="file" id="edit-frontpage-banner-images-upload" name="files[frontpage_banner_images]" size="22" class="form-file">
    <input type="submit" id="edit-frontpage-banner-images-upload-button" name="frontpage_banner_images_upload_button" value="Upload" class="form-submit ajax-processed">
    <input type="hidden" name="frontpage_banner_images[fid]" value="0">
  </div>
</div>

如您所见,我的 #attributes 中的 testclass 应用于包装 div 而不是文件输入。所以 multiple 属性没有做任何事情。

这就是我想要实现的目标(Photoshopped):

感谢任何关于如何实现这一点的帮助。

多重选项好像不是supported. Then again you are using it under the #attributes. This would cause IMO the html element to have an atttribute multiple, but I don't see anything in /modules/file/file.js to pick up on that, so that's presumably why it's not doing anything。 按照建议 here.

,您最好使用 plupload