/news/wp-admin/async-upload.php

https://github.com/dzachry/inferno-Demo · PHP · 56 lines · 37 code · 9 blank · 10 comment · 15 complexity · 47eac6954e325c6f5e7d10c186288dbc MD5 · raw file

  1. <?php
  2. /**
  3. * Accepts file uploads from swfupload or other asynchronous upload methods.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. if ( defined('ABSPATH') )
  9. require_once(ABSPATH . 'wp-load.php');
  10. else
  11. require_once('../wp-load.php');
  12. // Flash often fails to send cookies with the POST or upload, so we need to pass it in GET or POST instead
  13. if ( is_ssl() && empty($_COOKIE[SECURE_AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
  14. $_COOKIE[SECURE_AUTH_COOKIE] = $_REQUEST['auth_cookie'];
  15. elseif ( empty($_COOKIE[AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
  16. $_COOKIE[AUTH_COOKIE] = $_REQUEST['auth_cookie'];
  17. unset($current_user);
  18. require_once('admin.php');
  19. header('Content-Type: text/plain; charset=' . get_option('blog_charset'));
  20. if ( !current_user_can('upload_files') )
  21. wp_die(__('You do not have permission to upload files.'));
  22. // just fetch the detail form for that attachment
  23. if ( isset($_REQUEST['attachment_id']) && ($id = intval($_REQUEST['attachment_id'])) && $_REQUEST['fetch'] ) {
  24. if ( 2 == $_REQUEST['fetch'] ) {
  25. add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2);
  26. echo get_media_item($id, array( 'send' => false, 'delete' => false ));
  27. } else {
  28. echo get_media_item($id);
  29. }
  30. exit;
  31. }
  32. check_admin_referer('media-form');
  33. $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
  34. if (is_wp_error($id)) {
  35. echo '<div id="media-upload-error">'.wp_specialchars($id->get_error_message()).'</div>';
  36. exit;
  37. }
  38. if ( $_REQUEST['short'] ) {
  39. // short form response - attachment ID only
  40. echo $id;
  41. }
  42. else {
  43. // long form response - big chunk o html
  44. $type = $_REQUEST['type'];
  45. echo apply_filters("async_upload_{$type}", $id);
  46. }
  47. ?>