- Timestamp:
- 02/12/2015 01:14:47 AM (10 years ago)
- Location:
- trunk/src/wp-admin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/async-upload.php
r30649 r31429 33 33 require_once( ABSPATH . 'wp-admin/admin.php' ); 34 34 35 header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); 36 35 37 if ( isset( $_REQUEST['action'] ) && 'upload-attachment' === $_REQUEST['action'] ) { 36 38 include( ABSPATH . 'wp-admin/includes/ajax-actions.php' ); … … 46 48 wp_die( __( 'You do not have permission to upload files.' ) ); 47 49 } 48 49 header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );50 50 51 51 // just fetch the detail form for that attachment -
trunk/src/wp-admin/includes/ajax-actions.php
r31400 r31429 1846 1846 function wp_ajax_upload_attachment() { 1847 1847 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 */ 1848 1853 1849 1854 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 ) 1853 1861 ) ); 1862 1863 wp_die(); 1854 1864 } 1855 1865 … … 1857 1867 $post_id = $_REQUEST['post_id']; 1858 1868 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 ) 1862 1875 ) ); 1876 1877 wp_die(); 1863 1878 } 1864 1879 } else { … … 1872 1887 $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] ); 1873 1888 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(), 1876 1908 '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 ) 1887 1910 ) ); 1911 1912 wp_die(); 1888 1913 } 1889 1914 … … 1899 1924 wp_die(); 1900 1925 1901 wp_send_json_success( $attachment ); 1926 echo wp_json_encode( array( 1927 'success' => true, 1928 'data' => $attachment, 1929 ) ); 1930 1931 wp_die(); 1902 1932 } 1903 1933
Note: See TracChangeset
for help on using the changeset viewer.