]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/async-upload.php
Wordpress 2.6.2
[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-load.php');
9 else
10         require_once('../wp-load.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 ( 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
20 header('Content-Type: text/plain; charset=' . get_option('blog_charset'));
21
22 if ( !current_user_can('upload_files') )
23         wp_die(__('You do not have permission to upload files.'));
24
25 // just fetch the detail form for that attachment       
26 if ( ($id = intval($_REQUEST['attachment_id'])) && $_REQUEST['fetch'] ) {
27         echo get_media_item($id);
28         exit;
29 }
30
31 check_admin_referer('media-form');
32
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
39 if ( $_REQUEST['short'] ) {
40         // short form response - attachment ID only
41         echo $id;
42 }
43 else {
44         // long form response - big chunk o html
45         $type = $_REQUEST['type'];
46         echo apply_filters("async_upload_{$type}", $id);
47 }
48
49 ?>