You are here

function imageeditor_upload in Image Editor 7

Same name and namespace in other branches
  1. 6 imageeditor.module \imageeditor_upload()

AJAX callback to upload the image to external service.

1 string reference to 'imageeditor_upload'
imageeditor_menu in ./imageeditor.module
Implements hook_menu().

File

./imageeditor.pages.inc, line 39
Different pages for Image Editor module.

Code

function imageeditor_upload($codename) {
  $plugin = imageeditor_info('uploader', $codename);
  global $base_url;

  // TODO: need to fix this somehow... @see imageeditor_inline_url_to_uri().
  $filepath = '@' . drupal_realpath(str_replace($base_url . '/', '', rawurldecode($_POST['url'])));
  $post = $filepath;
  if ($post_callback = ctools_plugin_get_function($plugin, 'post_callback')) {
    $post = $post_callback($filepath);
  }
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_VERBOSE, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
  curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_URL, $plugin['upload_url']);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  $response = curl_exec($ch);
  curl_close($ch);
  $output = '';
  if ($response_callback = ctools_plugin_get_function($plugin, 'response_callback')) {
    $output = $response_callback($response);
  }
  drupal_json_output($output);
  drupal_exit();
}