You are here

function fupload_filetransfer in Image FUpload 6.2

Same name and namespace in other branches
  1. 6.3 image_fupload.module \fupload_filetransfer()
  2. 6 image_fupload.module \fupload_filetransfer()
1 string reference to 'fupload_filetransfer'
image_fupload_menu in ./image_fupload.module
Implementation of hook_menu().

File

./image_fupload.module, line 223

Code

function fupload_filetransfer() {

  // huh.. swfUpload sends some data...let's see
  global $user;
  $sid = $_POST['PHPSESSID'];

  // validate given session id
  $result = db_query("SELECT * FROM {sessions} WHERE sid = '%s' AND hostname = '%s' LIMIT 0 , 1", $sid, ip_address());
  $upload_user = db_fetch_object($result);
  if (!empty($upload_user)) {

    // Get users profile
    $user = user_load(array(
      'uid' => $upload_user->uid,
    ));

    // Adapt to drupal files structure
    $_FILES['files']['name']['image'] = $_FILES['Filedata']['name'];
    $_FILES['files']['type']['image'] = $_FILES['Filedata']['type'];
    $_FILES['files']['tmp_name']['image'] = $_FILES['Filedata']['tmp_name'];
    $_FILES['files']['error']['image'] = $_FILES['Filedata']['error'];
    $_FILES['files']['size']['image'] = $_FILES['Filedata']['size'];

    // Validators for file_save_upload().
    $validators = array(
      'file_validate_is_image' => array(),
      'file_validate_size' => array(
        variable_get('image_max_upload_size', 800) * 1024,
      ),
    );
    if ($file = file_save_upload('image', $validators)) {
      $image = image_get_info($file->filepath);

      // Get real mime-type
      if (!db_query("UPDATE {files} SET filename = '%s', filemime = '%s' WHERE fid = %d LIMIT 1", IMAGE_UNMACHINED, $image['mime_type'], $file->fid)) {
        drupal_set_header('HTTP/1.1 405 Upload Error');
      }
      print 'OK';

      // Reply something to satisfy swfUpload
    }
    else {
      drupal_set_header('HTTP/1.1 408 Image Error');
    }
  }
  else {
    drupal_access_denied();
  }
}