Support

Account

Home Forums ACF PRO Image upload size limit on front-end form

Solved

Image upload size limit on front-end form

  • Hi

    I have a front-end form that creates a new ‘pending/draft’ post. I’m asking visitors to submit images via the front-end form with a maximum file size of 5mb. I’ve overridden the default WordPress upload limit to 5mb which works for me when I’m logged in as an admin, but when I log out the front-end form still won’t let visitors upload an image that is more than 2mb.

    In the image field settings I also have the Maximum file size set to 5mb.

    Here’s my code in the functions file:

    function my_pre_save_post( $post_id )
    {
        // check if this is to be a new post
        if( $post_id != 'new' )
        {
            return $post_id;
        }
    
        // Create a new post
        $post = array(
            'post_status'  => 'pending' ,
         // 'post_title' => 'A title, maybe a $_POST variable',
             'post_title' => $_POST['acf']['field_55c9d6feda3a7'],
            'post_type'  => 'interpreted'
        );
    
        // insert the post
        $post_id = wp_insert_post( $post );
    
        // update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
    
        // return the new ID
        return $post_id;
    }
    
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );

    And the form code:

    <?php
    
    acf_form_head();
    
    get_header();
    
    the_post();
    
    ?>
    
    	<?php
    	$args = array(
    		'post_id' => 'new',
    		'field_groups' => array(233, 160),
    		'form' => true,
    		'submit_value' => 'Submit Entry',
    		'html_after_fields' => '<input type="hidden" name="post_type" value="cab_submission">',
    		'return' => 'http://www.cambridgerules1848.com/thank-you',
    		'form_attributes' => array(
         		'enctype' => 'multipart/form-data',
         		'autocomplete' => 'false'
    )
    			);
    			acf_form( $args );
    			?>
  • Problem solved! Because the image field settings already specified ‘MB’ at the end of the field, I was only inserting the numerical value, whereas it actually needs the mb repeating – 5mb not just the 5.

    Hopefully this might help out someone else.

  • More than likely you’ll need to alter the image size limit (upload_max_filesize) on the server php.ini settings. It will depend on your hosting environment exactly how you do that.

  • I may have found a WP filter that will let you change the upload limit https://developer.wordpress.org/reference/hooks/upload_size_limit/

  • Heh, and you figured it out while I was looking. Thanks for sharing.

  • No worries, such a silly gotcha. I wonder if that could be clearer or added to the docs somewhere.

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

You must be logged in to reply to this topic.