Great Module, more details needed

tmbejoy - February 3, 2008 - 18:44
Project:Drupal FTP
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:critical
Assigned:Unassigned
Status:active
Description

Hi aaron,
at http://drupal.org/project/drupal_ftp you said " I made a custom module using this as an API that will copy Image files (during upload) to an ftp server, so they may be served from off-server. " This would be really great if we can store images in different servers one after other. I could save lots of webspace and bandwidth. I am very much interested in this module please provide more details about your custom module.

thanks
Bejoy Thomas

#1

Mark B - March 27, 2008 - 11:46

I'm working on something similar. I'm building a site based around video sharing, and we need to upload the video files to a video hosting provider. I'm using the mediafield CCK module to get the video files uploaded by users, and then in videofield.module I've added an implementation of hook_nodeapi:

/**
* Implementation of hook_nodeapi().
*/
function videofield_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'submit':
      if($node->type == 'video') {
        $ftp = drupal_ftp_ftp_object();
        drupal_ftp_file_to_ftp($node->field_video_file[0]['filepath'], $node->field_video_file[0]['filename'], '/public_html/', $ftp); 
      }
      break;
  }
}

There are a couple of issues with this:

  1. the file uploaded has the original filename as specified by the uploading user - if another file exists with the same name, Drupal increments the filename in your Drupal files directory, but this ftp doesn't use that incremented filename
  2. there's a delay when the user initially uploads the file (i.e. when it is uploaded to the /tmp directory on the Drupal server), then another delay when they submit the node (i.e. when it is sent to the FTP server). This may not be a big deal for images, but it is a real problem for videos

I'm sure the first issue can be overcome by making the FTP call later in the file submission process (i.e. after the incremented unique filename has been generated), but I've only been working with Drupal two weeks, so am not sure where to look yet - perhaps someone else can offer advice on this.

The second issue (along with some other requirements) mean that I'm not taking this process any further, and will instead use an asynchronous batch FTP process, but this sample should at least get you off in the right direction, and shows how simple it is to use the FTP API - thanks Aaron!

 
 

Drupal is a registered trademark of Dries Buytaert.