I have a website where user can register and update their profile info. Subscriber user role assigned to them. For updating image i am using wp media uploader. When a subscriber user upload their profile image using and choose file locally, it show me error

An error occurred in the upload. Please try again later.

And if i refresh page, it logged out the user.

The same procedure if followed by admin user then everything works fine.

Here is the code for the image uploading:

 <i class="fa fa-cloud-upload" ></i>
 <input class="criteria-file button" id="your_image_url_button" type="button" value="Upload File"/>
 <script>

                                var image_custom_uploader_file;

                                var $thisItem = '';



                                jQuery(document).on('click','.criteria-file', function(e) {

                                    e.preventDefault();



                                    $thisItem = jQuery(this);



                                    //If the uploader object has already been created, reopen the dialog

                                    if (image_custom_uploader) {

                                        image_custom_uploader.open();

                                        return;

                                    }



                                    //Extend the wp.media object

                                    image_custom_uploader_file = wp.media.frames.file_frame = wp.media({

                                        title: 'Choose File',

                                        button: {

                                            text: 'Choose File'

                                        },

                                        multiple: false

                                    });



                                    //When a file is selected, grab the URL and set it as the text field's value

                                    image_custom_uploader_file.on('select', function() {

                                        attachment = image_custom_uploader_file.state().get('selection').first().toJSON();

                                        var url = '';

                                        url = attachment['url'];

                                        var filename ='';

                                        filename = attachment['filename'];

                                        $thisItem.parent().parent().parent().find('.criteria-image-url').val(url);

                                        $thisItem.parent().parent().parent().find('.criteria-image-url-name').val(filename);

                                        $thisItem.parent().parent().parent().find('.file-name').val(filename);

                                        $thisItem.parent().parent().parent().find('.criteria-file').css("display", "none");

                                        $thisItem.parent().parent().parent().find('.criteria-file-remove').css("display", "block");

                                        $thisItem.parent().parent().parent().find(".fa-cloud-upload").css("display", "none");

                                        $thisItem.parent().parent().parent().find(".fa-trash-o").css("display", "block");

                                    });



                                    //Open the uploader dialog

                                    image_custom_uploader_file.open();

                                 });



                                 jQuery(document).on('click','.criteria-file-remove', function(e) {

                                    jQuery(this).parent().parent().parent().find('.criteria-image-url').val('');

                                    jQuery(this).parent().parent().parent().find('.criteria-image-url-name').val('');

                                    jQuery(this).parent().parent().parent().find('.file-name').val('');

                                    jQuery(this).parent().parent().parent().find('.criteria-file').css("display", "block");

                                    jQuery(this).parent().parent().parent().find(".fa-cloud-upload").css("display", "block");

                                    jQuery(this).parent().parent().parent().find(".fa-trash-o").css("display", "none");

                                    jQuery(this).css("display", "none");

                                 });

                            </script>

I tried to increase define( ‘WP_MEMORY_LIMIT’, ‘512M’ ); but didn’t work.

Anyone can suggest me how i can fix this issue.

Thanks in Advance.

Read more here: User become logged out when upload image from wp media wordpress


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: