source: trunk/www.guidonia.net/wp/wp-admin/async-upload.php@ 44

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