This snippet allows multiple images upload with ImageField module via FTP Client.
It uses CCK Computed Field to manage multiple files upload.

Configuration

We need to create a directory in file system and 4 CCK fields:

  1. Create a folder (we call it ftp_gals) in sites > default > files where folders containing images will be stored.
  2. Create a single on-off checkbox element (we call it field_reload_gallery) and set allowed values ("Import now" and "Don't import" should sound good).
  3. Create a textfield element (field_new_gallery). You can call it Folder name.
  4. Create a imagefield element (field_g_slideshow) and set number of values to unlimited.
  5. Create a CCK Computed field and paste this code in Computed Code textarea:
    $boolean_check_on = "Import now";
    $boolean_check_off = "Don't import";
    // these are the two allowed values of the CCK single on-off checkbox element which user checks for starting import process
    
    $your_galleries_folder = "ftp_gals";
    // the folder under /sites/default/files which contains user's galleries folders
    
    if ($node->field_reload_gallery[0]['value'] == $boolean_check_on) {
    // field_reload_gallery is the CCK single on-off checkbox element which user check for starting importation
    
      $tg_gallery = file_directory_path() . "/". $your_galleries_folder . "/" . trim($node->field_new_gallery[0]['value']);
      // field_new_gallery is the CCK textfield element where user write gallery's folder name
    
      $node->field_reload_gallery[0]['value'] = $boolean_check_off;
      // setting off checkbox for any next node editing
    
      $imgs = file_scan_directory($tg_gallery, '.*');
      sort($imgs);
      $node->field_g_slideshow = array();
      // field_g_slideshow is the CCK imagefield element which will be populated with images data
      
      foreach ($imgs as $file_img) {
        $this_file_path = $file_img->filename;
        $ins_file = array(
          'list' => 1,
          'filename' => basename($this_file_path),
          'filepath' => $this_file_path,
          'filemime' => file_get_mimetype($this_file_path),
          'filesize' => filesize($this_file_path),
          'uid'      => 1,
          'status'   => 1,
          'timestamp'=> time()
        );
        drupal_write_record('files',$ins_file);
        $node->field_g_slideshow[] = (field_file_load($this_file_path));
      }
      // files information are now stored in database
      // uid = 1 is drupal superuser, you can change it
      
    }
    $node_field[0]['value'] = "";
    // return this field empty
    
    
  6. Give FTP access to ftp_gals to the user.

How to upload multiple images:

  1. Create a folder (gal1) containing images and upload it via FTP (in sites > default > files > ftp_gals). (You can use any FTP Client, as Filezilla, Duckload and so on)
  2. Create a node and put folder name (gal1) in the appropriated textfield element (field_new_gallery).
  3. Check the checkbox (field_reload_gallery).
  4. Save the node!

Important

When user checks the box and save the node imagefield CCK element will be resetted before import.

Modules used

Drupal Core 6.22
CCK 6.x-2.9
FileField 6.x-3.10
ImageField 6.x-3.10
Computed Field 6.x-1.0-beta5

Comments

adr75’s picture

This snippet is exactly what I am looking for, however I can't get it to work. Does anyone have ideas on how to check what is going wrong? Followed the instructions to the letter, maybe I am overlooking something small?

adr75’s picture

The snippet works if you add forward slashes to the path of the gallery folder, as in:

$tg_gallery = file_directory_path() . "/". $your_galleries_folder . "/" . trim($node->field_new_gallery[0]['value']);

Thanks for this useful snippet!

Bitvark’s picture

I've corrected it in the example.
Happy it has been useful!