Support

Account

Home Forums Front-end Issues Front-end form image upload issues

Solving

Front-end form image upload issues

  • Hi,
    First of all – Elliot, you really are a superstar for developing ACF.

    Sp, I’m using the front-end for to allow users to upload their own posts. Everything works fine except when it comes to uploading images. Has anyone found a work-around for this. It seems you’re only able to upload images if you’re logged in as a Contributor/Editor but I was hoping to allow anyone using the form to upload images..

    I’ve read this post but that relates to change user roles. I understand that this is probably a WordPress issue but since I’m using the ACF forms i thought someone might be able to help out? Or is there another option to include images into the post??

  • I also had a similar issue, but the only way to do this is to edit the WordPress role. You can do that via the User Role Editor plugin or a similar one. Just tick the upload_files capabilities for subscriber.

  • It’s still giving me the upload error. I’ve tried using the ‘Contributor’ Role with:
    edit_others_pages
    edit_others_posts
    edit_pages
    edit_posts
    edit_private_pages
    edit_private_posts
    edit_published_pages
    edit_published_posts

    All those checked and it still won’t let me upload.

  • Tried as editor, contributor and subscriber – the only way to upload images in the front end form is via Administrator role 🙁

  • You need to check the upload_files capability.

  • Sorry – yes, that was a given. I’ve got that checked on all roles.

  • hi, I had that problem a while a go where no roles could upload images.
    in the end it was because of the “upload” folder CHMOD, it worked fine on my server but on the final host i had to tweak that with the host provider.

  • Hi,
    I have the same problem, and cant find a solution for change upload_files capability for non logged user.

  • Bashed my head over this for most of today. Finally got it to work.

    I was limiting roles from accessing the backend.

    function restrict_admin()
    {
        if ( ! current_user_can( 'update_core' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {
                    wp_redirect( site_url('/apply') );
        }
    }
    add_action( 'admin_init', 'restrict_admin', 1 );

    This conflicted with the AJAX of the image uploader. Check your theme’s function.php and plugins to see if there is any similar conflict.

  • @ben[email protected] are u uploading image from fontend for non logged user?
    I tried your solution but it doesn’t work for me

    Thanks

  • Ok I found a solution to upload an image for non logged user from a front end form.

    This method just upload the file in the media library and return the attachment id => $attachment_id (in functions.php)

    So, to set the image like featured image for example, use the set_post_thumbnail method:

    http://codex.wordpress.org/Function_Reference/set_post_thumbnail

    Hope to help you.

    Matteo

  • @Matteo@matteo.legittimo
    this working fine for image upload, but how do i use it to set it as “”featured image”

    i’m not familiar with ACF codes.

    thanks in advance.

  • Had the same problem on a project I’m working on where subcribers / contributor’s are using the ACF_Form() to create new posts and also to upload images through the gallery field.

    The problem occurs with current_user_can(‘edit_post’, $post_id ) returns false (this is checked when the user tries to upload an image through the media uploader ) if the post isn’t already created….so while using the form..you first want to create the post..and THEN let the user upload images through the gallery field. This worked for me… not the perfect sollution…anyone else have a better one, please let me know 🙂

  • Hello,

    Thanks for your comment. But I didn’t understood it well. What have we to do in the code ?

  • I ran into the same problem. No upload for me in the frontend. As tgnsd mentioned earlier when the backend is disabled the ajax thing won’t work. I changed my code to this and the upload worked!

    add_action( 'init', 'blockusers_init' );
    function blockusers_init() {
    if ( is_admin() && ! current_user_can( 'administrator' ) &&
    ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
    wp_redirect( home_url() );
    exit;
    }
    }

    I get this from here: https://premium.wpmudev.org/blog/limit-access-to-your-wordpress-dashboard/

Viewing 15 posts - 1 through 15 (of 15 total)

The topic ‘Front-end form image upload issues’ is closed to new replies.