You are here

function flash_prepare in Flash Node 5

Implementation of hook_prepare().

File

./flash.module, line 163

Code

function flash_prepare(&$node, $field_name) {
  if (is_null($field_name)) {
    $field_name = 'flashfile';
  }

  // check if the upload is valid
  if ($file = file_check_upload($field_name)) {

    // if it is then save it to the flash/temp folder
    $file = file_save_upload($field_name, _flash_filename($file->filename, TRUE));

    // if the upload succeeds...
    if ($file) {

      // ...check if the mime type wasn't flash
      if (strtolower($file->filemime) != 'application/x-shockwave-flash') {
        watchdog($field_name, t('flash was given %type for upload.', array(
          '%type' => $node->file->filemime,
        )));
        form_set_error($field_name, t('The specified file is not a valid Flash format.'));

        // delete the uploaded file in case it is unsafe
        file_delete($file->filepath);
        return;
      }
    }
    else {
      return;
    }

    // add data to the $node->flash object
    $node->flash['_flash'] = $file->filepath;
    $node->flash['filemime'] = $file->filemime;
    $node->new_file = TRUE;
  }

  // try to get the file settings for this file, using image_get_info
  $info = image_get_info(file_create_path($node->flash['_flash']));
  $node->flash['_height'] = $info['height'];
  $node->flash['_width'] = $info['width'];
}