• Resolved robinzimmer1989

    (@robinzimmer1989)


    Hi there, first of all: Your plugin is awesome, thank you so much for this!

    I just have a tiny issue with email attachments. I’m using a file upload field with the ‘basic’ uploader. And everything is working fine here: The file gets uploaded to the server and the saved form entry contains the link to the file! But for some reason it’s not showing up in the email. Below the field name is just an “h” with no link. Do you know what to do?

    Let me know if you have any questions.

    Best regards
    Robin

    $args = array(
    ‘uploader’ => ‘basic’,
    ‘submit_text’ => ‘Send Request’
    );

    advanced_form( ‘form_5acfceaaac1de’, $args );

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi and thank you!

    I just tried a similar scenario with the basic uploader and the file with link showed up in the email. Could you check if your uploads directory contains the file after submission?

    Thread Starter robinzimmer1989

    (@robinzimmer1989)

    Hi Fabian, okay I guess I found the error:
    I changed the return value of the acf field from “File URL” to “File Array” and now the link is showing up in the email.

    Is there a way to change the filename during the upload process with a hook?

    Best regards
    Robin

    Plugin Author fabianlindfors

    (@fabianlindfors)

    That sounds like a good solution! I might add better support for file fields in a future release with support for both “File URL” and “File array”.

    Regarding uploads it might be a challenge. My plugin uses a function provided by ACF to automatically handle uploads and unfortunately ACF doesn’t provide any hooks for it. There does exist a WordPress hook which is triggered whenever a file is uploaded called wp_create_file_in_uploads (https://developer.wordpress.org/reference/hooks/wp_create_file_in_uploads/). You could probably hook into this, check if AF()->submission is not null, and then change the file name. I realize this is quite cumbersome but it seems to be the best solution for the moment. Hopefully I can provide my own uploading implementation in the future with better hooks!

    Hope this helps!

    Thread Starter robinzimmer1989

    (@robinzimmer1989)

    Hi Fabian, I’ve found a nice hook to change the filename, but I have problems to check for a AF form submission as you suggested. For now I just check if the file gets uploaded via the frontend or backend by inspecting the url.

    Do you have a more elegant solution for this?

    <?php
    function renameUploadedFiles($filename) {
    
        $info = pathinfo($filename);
        $ext  = empty($info['extension']) ? '' : '.' . $info['extension'];
    
        $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
        
        if (strpos($url, 'wp-admin') == false):
            $filename = bin2hex(openssl_random_pseudo_bytes(16));
        endif;
    
        return $filename . $ext;
    }
    add_filter('sanitize_file_name', 'renameUploadedFiles', 10);
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Email attachment missing’ is closed to new replies.