wp_check_filetype_and_ext example

'php.ini',
                'post_max_size',
                'upload_max_filesize'
            );
        }

        return call_user_func_array( $upload_error_handler, array( &$file$error_msg ) );
    }

    // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.     if ( $test_type ) {
        $wp_filetype     = wp_check_filetype_and_ext( $file['tmp_name']$file['name']$mimes );
        $ext             = empty( $wp_filetype['ext'] ) ? '' : $wp_filetype['ext'];
        $type            = empty( $wp_filetype['type'] ) ? '' : $wp_filetype['type'];
        $proper_filename = empty( $wp_filetype['proper_filename'] ) ? '' : $wp_filetype['proper_filename'];

        // Check to see if wp_check_filetype_and_ext() determined the filename was incorrect.         if ( $proper_filename ) {
            $file['name'] = $proper_filename;
        }

        if ( ( ! $type || ! $ext ) && ! current_user_can( 'unfiltered_upload' ) ) {
            return call_user_func_array( $upload_error_handler, array( &$file__( 'Sorry, you are not allowed to upload this file type.' ) ) );
        }

    public function handle_upload() {
        if ( empty( $_FILES ) ) {
            return;
        }

        check_admin_referer( 'custom-background-upload', '_wpnonce-custom-background-upload' );

        $overrides = array( 'test_form' => false );

        $uploaded_file = $_FILES['import'];
        $wp_filetype   = wp_check_filetype_and_ext( $uploaded_file['tmp_name']$uploaded_file['name'] );
        if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
            wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
        }

        $file = wp_handle_upload( $uploaded_file$overrides );

        if ( isset( $file['error'] ) ) {
            wp_die( $file['error'] );
        }

        $url      = $file['url'];
        
$post_id = null;
    }

    $post_data = ! empty( $_REQUEST['post_data'] ) ? _wp_get_allowed_postdata( _wp_translate_postdata( false, (array) $_REQUEST['post_data'] ) ) : array();

    if ( is_wp_error( $post_data ) ) {
        wp_die( $post_data->get_error_message() );
    }

    // If the context is custom header or background, make sure the uploaded file is an image.     if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ), true ) ) {
        $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name']$_FILES['async-upload']['name'] );

        if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
            echo wp_json_encode(
                array(
                    'success' => false,
                    'data'    => array(
                        'message'  => __( 'The uploaded file is not a valid image. Please try again.' ),
                        'filename' => esc_html( $_FILES['async-upload']['name'] ),
                    ),
                )
            );

            
/** * Uploads the file to be cropped in the second step. * * @since 3.4.0 */
    public function step_2_manage_upload() {
        $overrides = array( 'test_form' => false );

        $uploaded_file = $_FILES['import'];
        $wp_filetype   = wp_check_filetype_and_ext( $uploaded_file['tmp_name']$uploaded_file['name'] );

        if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
            wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
        }

        $file = wp_handle_upload( $uploaded_file$overrides );

        if ( isset( $file['error'] ) ) {
            wp_die( $file['error']__( 'Image Upload Error' ) );
        }

        
Home | Imprint | This part of the site doesn't use cookies.