• Resolved markilfin

    (@markilfin)


    Hi,
    i’m using ACF PRO plugin to create frontend form where any user( even anonymous ) can add data and upload images. I want to keep all uploaded images in “user_uploads” folder. I tried to achive this by using FileBird API, here is an example of my code:

    function move_images_to_correct_folder ( $post_id, $type, $args, $form, $action ) {
    	// 
    	$folderID = '8';
    	$api_key = 'FkrUV7ONns8duR6CM3GiNyx6YjE7VAHzeziEGpNj';
    	// 
    	$images = get_field( 'add_marker_step_2_images' );
    	if ( $images ) {
    		// 
    		$ids = array();
    		// 
    		foreach ( $images as $single_image ) {
    			array_push( $ids, $single_image['image']['id'] );
    		}
    		// 
    		$link = get_site_url() . '/wp-json/filebird/public/v1/folder/set-attachment/?folder=' . $folderID . '&ids=' . json_encode( $ids ) . '&token=' . $api_key;
    		// 
    		$response = wp_remote_post( $link );
    	}
    }
    
    add_action( 'acfe/form/submit/post/form=add-marker', 'move_images_to_correct_folder', 10, 5 );

    but it fails. In response it says:

    "success":false
    "data":{"mess":"Validation failed"}

    here is an example of response. What am i doing wrong? I’m using FileBird Lite version.

    • This topic was modified 3 years, 9 months ago by markilfin.
    • This topic was modified 3 years, 9 months ago by markilfin.
    • This topic was modified 3 years, 9 months ago by markilfin.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Ninja Team

    (@ninjateam)

    Hello @markilfin ,

    Please try use this code, let us know if it helps.

    function move_images_to_correct_folder ( $post_id, $type, $args, $form, $action ) {
                // 
                $folderID = '8';
                $api_key = 'FkrUV7ONns8duR6CM3GiNyx6YjE7VAHzeziEGpNj';
                // 
                $images = get_field( 'add_marker_step_2_images' );
                if ( $images ) {
                    // 
                    $ids = array();
                    // 
                    foreach ( $images as $single_image ) {
                        array_push( $ids, $single_image['image']['id'] );
                    }
                    // 
                    $link = get_site_url() . '/wp-json/filebird/public/v1/folder/set-attachment/';
                    // 
                    $response = wp_remote_post( $link, array(
                            'method'      => 'POST',
                            'timeout'     => 45,
                            'body'        => array(
                                'folder' => $folderID,
                                'ids' => $ids,
                                'token' => $api_key
                            ),
                    ));
                }
            }
            add_action( 'acfe/form/submit/post/form=add-marker', 'move_images_to_correct_folder', 10, 5 );
    Thread Starter markilfin

    (@markilfin)

    Thank you for your quick answer. Yes, this helped me a lot.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Place new images into folder’ is closed to new replies.