• I was one of the people with the infinite spinning wheel on the last major version. I am happy to see that problem was addressed.

    Now that I’ve updated to the latest version of CF7 (5.4 with CF7 Smart Grid Design Extension 4.10.0), I have a new problem. Media uploaded via the file upload link doesn’t upload. The new “Thank you for your message. It has been sent.” message is more reassuring than the infinite spinning wheel, but alas, it is misleading.

    The field with which I am uploading appears as

    [file* field_image limit:10000000 filetypes:jpg|gif|png|jpeg class:field-image]

    in Smart Grid.

    The results are that the images appear in the media library as blank gray squares.

    ![Gray Boxes](https://unavoidabledisaster.com/wp-content/uploads/2021/04/Screen-Shot-2021-04-02-at-2.58.33-PM.png)

    Details in the media library slow no file name, no file type, no file size. I have tested dropping media directly into the media library and that works fine.

    ![No metadata](https://unavoidabledisaster.com/wp-content/uploads/2021/04/Screen-Shot-2021-04-02-at-3.04.26-PM.png)

    While the problem could lie in the post submit code that handles the submission, none of that has changed in a year. Only CF7 has changed.

    Any hints?

    • This topic was modified 3 years, 7 months ago by Wes Modes.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter Wes Modes

    (@wmodes)

    Further investigation shows that the image does get mailed, so the form is uploading the file properly. But something changed in the new version of how it internally handles uploaded files. Here’s the relevant PHP in functions.php that handles uploaded images within the function that constructs a WP CPT.

    // IMAGE
    // Retrieving and inserting uploaded image as featured image
    // CF7 uploads the image and puts it in a temporary directory,
    //      deleting it after the mail is sent
    // Before it deletes it, we will move into our media library,
    //      and attach it to our post
    //
    // get file upload info from form
    $uploadedFiles = $submission->uploaded_files();
    // if we have an uploaded image...
    if( isset($posted_data['field_image']) ){
        // move image from temp folder to upload folder
        $imageUpload = wp_upload_bits($posted_data['field_image'], null,
            file_get_contents($uploadedFiles['field_image']));
        // PC::debug("imageUpload:", print_r($imageUpload, True));
        // echo ("imageUpload:", print_r($imageUpload, True));
        //
        require_once(ABSPATH . 'wp-admin/includes/admin.php');
        // construct array to register this image
        $filename = $imageUpload['file'];
        $attachment = array(
            'post_mime_type' => $imageUpload['type'],
            'post_parent' => $post_id,
            'post_title' => $posted_data['field_title'] . ' - ' .
                            $posted_data['field_contributor'],
            'post_content' => $posted_data['field_info'],
            'post_status' => 'inherit'
        );
        // attach image to this post
        $attachment_id = wp_insert_attachment( $attachment, $filename, $post_id );
        // PC::debug("attachment_id:", print_r($attachment_id, True));
        // echo ("attachment_id:", print_r($attachment_id, True));
        // if we succeeded...
        if (!is_wp_error($attachment_id)) {
            require_once(ABSPATH . 'wp-admin/includes/image.php');
            $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
            // PC::debug("attachment_data:", print_r($attachment_data, True));
            wp_update_attachment_metadata( $attachment_id,  $attachment_data );
            set_post_thumbnail( $post_id, $attachment_id );
            // add image id (attchment id) to ad_image field
            update_field( 'ad_image', $attachment_id, $post_id );
        }
    }

    This is called by:

    add_action('wpcf7_before_send_mail', 'save_my_form_data_to_my_cpt', 10, 3);

    • This reply was modified 3 years, 7 months ago by Wes Modes.
    • This reply was modified 3 years, 7 months ago by Wes Modes.
Viewing 1 replies (of 1 total)
  • The topic ‘Images don’t upload’ is closed to new replies.