WordPress.org

Make WordPress Core

Changeset 31429


Ignore:
Timestamp:
02/12/2015 01:14:47 AM (6 years ago)
Author:
dd32
Message:

Prevent IE9 and lower displaying the download file dialogue when attempting to upload using the html4 Plupload handler.

The HTML4 Plupload handler uses a hidden iframe to POST the upload form,
Unfortunately Internet Explorer 9 doesn't support the application/json
content-type which wp_send_json_success() and requires text/html instead.

This partially reverts [30354], keeping the better error messages.

Fixes #31037 for trunk.

Location:
trunk/src/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/async-upload.php

    r30649 r31429  
    3333require_once( ABSPATH . 'wp-admin/admin.php' );
    3434
     35header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
     36
    3537if ( isset( $_REQUEST['action'] ) && 'upload-attachment' === $_REQUEST['action'] ) {
    3638    include( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
     
    4648    wp_die( __( 'You do not have permission to upload files.' ) );
    4749}
    48 
    49 header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
    5050
    5151// just fetch the detail form for that attachment
  • trunk/src/wp-admin/includes/ajax-actions.php

    r31400 r31429  
    18461846function wp_ajax_upload_attachment() {
    18471847    check_ajax_referer( 'media-form' );
     1848    /*
     1849     * This function does not use wp_send_json_success() / wp_send_json_error()
     1850     * as the html4 Plupload handler requires a text/html content-type for older IE.
     1851     * See https://core.trac.wordpress.org/ticket/31037
     1852     */
    18481853
    18491854    if ( ! current_user_can( 'upload_files' ) ) {
    1850         wp_send_json_error( array(
    1851             'message'  => __( "You don't have permission to upload files." ),
    1852             'filename' => $_FILES['async-upload']['name'],
     1855        echo wp_json_encode( array(
     1856            'success' => false,
     1857            'data'    => array(
     1858                'message'  => __( "You don't have permission to upload files." ),
     1859                'filename' => $_FILES['async-upload']['name'],
     1860            )
    18531861        ) );
     1862
     1863        wp_die();
    18541864    }
    18551865
     
    18571867        $post_id = $_REQUEST['post_id'];
    18581868        if ( ! current_user_can( 'edit_post', $post_id ) ) {
    1859             wp_send_json_error( array(
    1860                 'message'  => __( "You don't have permission to attach files to this post." ),
    1861                 'filename' => $_FILES['async-upload']['name'],
     1869            echo wp_json_encode( array(
     1870                'success' => false,
     1871                'data'    => array(
     1872                    'message'  => __( "You don't have permission to attach files to this post." ),
     1873                    'filename' => $_FILES['async-upload']['name'],
     1874                )
    18621875            ) );
     1876
     1877            wp_die();
    18631878        }
    18641879    } else {
     
    18721887        $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] );
    18731888        if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
    1874             wp_send_json_error( array(
    1875                 'message'  => __( 'The uploaded file is not a valid image. Please try again.' ),
     1889            echo wp_json_encode( array(
     1890                'success' => false,
     1891                'data'    => array(
     1892                    'message'  => __( 'The uploaded file is not a valid image. Please try again.' ),
     1893                    'filename' => $_FILES['async-upload']['name'],
     1894                )
     1895            ) );
     1896
     1897            wp_die();
     1898        }
     1899    }
     1900
     1901    $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data );
     1902
     1903    if ( is_wp_error( $attachment_id ) ) {
     1904        echo wp_json_encode( array(
     1905            'success' => false,
     1906            'data'    => array(
     1907                'message'  => $attachment_id->get_error_message(),
    18761908                'filename' => $_FILES['async-upload']['name'],
    1877             ) );
    1878         }
    1879     }
    1880 
    1881     $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data );
    1882 
    1883     if ( is_wp_error( $attachment_id ) ) {
    1884         wp_send_json_error( array(
    1885             'message'  => $attachment_id->get_error_message(),
    1886             'filename' => $_FILES['async-upload']['name'],
     1909            )
    18871910        ) );
     1911
     1912        wp_die();
    18881913    }
    18891914
     
    18991924        wp_die();
    19001925
    1901     wp_send_json_success( $attachment );
     1926    echo wp_json_encode( array(
     1927        'success' => true,
     1928        'data'    => $attachment,
     1929    ) );
     1930
     1931    wp_die();
    19021932}
    19031933
Note: See TracChangeset for help on using the changeset viewer.