]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/async-upload.php
1a37dceb96bf725f18e8de357dd4dd8292e7cbaf
[autoinstalls/wordpress.git] / wp-admin / async-upload.php
1 <?php
2
3 /* This accepts file uploads from swfupload or other asynchronous upload methods.
4
5 */
6
7 if ( defined('ABSPATH') )
8         require_once( ABSPATH . 'wp-config.php');
9 else
10     require_once('../wp-config.php');
11
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 ( empty($_COOKIE[AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
14         $_COOKIE[AUTH_COOKIE] = $_REQUEST['auth_cookie'];
15 unset($current_user);
16 require_once('admin.php');
17
18 header('Content-Type: text/plain');
19
20 if ( !current_user_can('upload_files') )
21         wp_die(__('You do not have permission to upload files.'));
22
23 // just fetch the detail form for that attachment       
24 if ( ($id = intval($_REQUEST['attachment_id'])) && $_REQUEST['fetch'] ) {
25         echo get_media_item($id);
26         exit;
27 }
28
29 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
30 if (is_wp_error($id)) {
31         echo '<div id="media-upload-error">'.wp_specialchars($id->get_error_message()).'</div>';
32         exit;
33 }
34
35 if ( $_REQUEST['short'] ) {
36         // short form response - attachment ID only
37         echo $id;
38 }
39 else {
40         // long form response - big chunk o html
41         $type = $_REQUEST['type'];
42         echo apply_filters("async_upload_{$type}", $id);
43 }
44
45 ?>