• I want to let my website user to upload files in a form and then send them attached to email. HOwever I cant find way to get links to those files. I used this code

    $attachment_links = array();
    
    			$attachments = get_posts(array(   'post_type' => 'attachment',
    											  'numberposts' => -1,
      											  'post_status' =>'any',
    											  'post_parent' => $post->ID
    										  ));
    
    			if ($attachments) {
    				foreach ( $attachments as $attachment ) {
    					        echo apply_filters( 'the_title' , $attachment->post_title );
    					$attachment_links[$attachment->ID]=the_attachment_link( $attachment->ID , true );
    				}
    			}
    
    			wp_mail( $emailTo, $subject, $body, $headers, $attachment_links );

    But that doesnt work. Actually the file being uploaded do not get attached to the post.

    https://www.ads-software.com/plugins/wp-multi-file-uploader/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author dholloran

    (@dholloran)

    It doesn’t attach the upload to the post it does add a hidden input to the file up loaders parent form if it is enclosed in form tags. The input has the attachment Id as it’s value so I would suggest using that on form submit.

    Thread Starter alaskaash

    (@alaskaash)

    In that case, how to know how many file are uploaded.

    Plugin Author dholloran

    (@dholloran)

    For each file uploaded the plugin will add a hidden input field name=”wp_multi_file_uploader_[NUMBER]” with [NUMBER] representing the amount of files starting at 1 and the value will be the uploads attachment id

    That is basically how it works I would check the $_POST or $_GET depending on your forms method and find all the keys contain wp_multi_file_uploader push them to an array or do something with they value.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how to get links to the file uploaded’ is closed to new replies.