You are here

function angular_media_callback_upload in CKEditor Widgets 7

Callback that handles and saves uploaded files.

This will respond to the URL on which plupoad library will upload files.

1 string reference to 'angular_media_callback_upload'
angular_media_menu in ./angular_media.module
Implements hook_menu().

File

./angular_media.module, line 196
Implementation of angular_media.module.

Code

function angular_media_callback_upload() {
  watchdog('angular_media', 'upload: $_FILES sent to server <pre>%f</pre>', array(
    '%f' => print_r($_FILES, 1),
  ));
  $destination = 'public://';

  //@todo
  $validators = array();
  $fieldName = 'files';

  // Manually construct $_FILES['files'] for Drupal's file_save_upload()
  $_FILES['files'] = array();
  $_FILES['files']['name'][$fieldName] = $_FILES['file']['name'];
  $_FILES['files']['type'][$fieldName] = $_FILES['file']['type'];
  $_FILES['files']['tmp_name'][$fieldName] = $_FILES['file']['tmp_name'];
  $_FILES['files']['error'][$fieldName] = $_FILES['file']['error'];
  $_FILES['files']['size'][$fieldName] = $_FILES['file']['size'];
  $file = file_save_upload($fieldName, $validators, $destination, FILE_EXISTS_RENAME);
  $file->status = 1;
  file_save($file);
  watchdog('angular_media', 'file uploaded <pre>%f</pre>', array(
    '%f' => print_r($file, 1),
  ));
  drupal_json_output(angular_media_simplify_file($file));
  exit;
}