upload_from_data example


    protected function insert_attachment( $request ) {
        // Get the file via $_FILES or raw data.         $files   = $request->get_file_params();
        $headers = $request->get_headers();

        if ( ! empty( $files ) ) {
            $file = $this->upload_from_file( $files$headers );
        } else {
            $file = $this->upload_from_data( $request->get_body()$headers );
        }

        if ( is_wp_error( $file ) ) {
            return $file;
        }

        $name       = wp_basename( $file['file'] );
        $name_parts = pathinfo( $name );
        $name       = trim( substr( $name, 0, -( 1 + strlen( $name_parts['extension'] ) ) ) );

        $url  = $file['url'];
        
Home | Imprint | This part of the site doesn't use cookies.