+/** Load WordPress Administration Bootstrap */
+require_once( dirname( __FILE__ ) . '/admin.php' );
+
+if (!current_user_can('upload_files'))
+ wp_die(__('You do not have permission to upload files.'));
+
+wp_enqueue_script('plupload-handlers');
+
+$post_id = 0;
+if ( isset( $_REQUEST['post_id'] ) ) {
+ $post_id = absint( $_REQUEST['post_id'] );
+ if ( ! get_post( $post_id ) || ! current_user_can( 'edit_post', $post_id ) )
+ $post_id = 0;
+}
+
+if ( $_POST ) {
+ $location = 'upload.php';
+ if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
+ check_admin_referer('media-form');
+ // Upload File button was clicked
+ $id = media_handle_upload( 'async-upload', $post_id );
+ if ( is_wp_error( $id ) )
+ $location .= '?message=3';
+ }
+ wp_redirect( admin_url( $location ) );
+ exit;
+}
+
+$title = __('Upload New Media');
+$parent_file = 'upload.php';