Hey. How are you?
- Are you using any integration or it’s the core file input from CF7?
- Is everything updated?
(It’s pretty strange as we send the URL for a copied file.)
Yeah I am using a plugin Multifile Upload Field for Contact Form 7
We support CF7 uploaded files (tag “file”).
However I’ll check it’s possible to add this support in a future release.
By now, maybe this code can help you:
<?php
add_filter( 'ctz_get_data_from_contact_form', 'multiline_files_contact_form', 10, 2 )
function multiline_files_contact_form( $data, $contact_form ) {
// Submission
$submission = WPCF7_Submission::get_instance();
$uploaded_files = ( ! empty( $submission ) ) ? $submission->uploaded_files() : [];
// Upload Info
$wp_upload_dir = wp_get_upload_dir();
$upload_path = CFTZ_UPLOAD_DIR . '/' . $contact_form->id() . '/' . uniqid();
$upload_url = $wp_upload_dir['baseurl'] . '/' . $upload_path;
$upload_dir = $wp_upload_dir['basedir'] . '/' . $upload_path;
$tags = $contact_form->scan_form_tags();
foreach ( $tags as $tag ) {
if ( $tag->basetype !== 'multilinefile' || empty( $uploaded_files[ $tag->name ] ) ) {
continue;
}
$files = $uploaded_files[ $tag->name ];
$copied_files = [];
foreach ( (array) $files as $file ) {
wp_mkdir_p( $upload_dir );
$filename = wp_unique_filename( $upload_dir, $tag->name . '-' . basename( $file ) );
if ( ! copy( $file, $upload_dir . '/' . $filename ) ) {
$submission = WPCF7_Submission::get_instance();
$submission->set_status( 'mail_failed' );
$submission->set_response( $contact_form->message( 'upload_failed' ) );
continue;
}
$copied_files[] = $upload_url . '/' . $filename;
}
$value = $copied_files;
if ( count( $value ) === 1 ) {
$value = $value[0];
}
// Support to "webhook" option (rename field value)
$key = $tag->name;
$webhook_key = $tag->get_option( 'webhook' );
if ( ! empty( $webhook_key ) && ! empty( $webhook_key[0] ) ) {
$key = $webhook_key[0];
}
$data[ $key ] = $value;
}
return $data;
}
It’s just a copy and past of our plugin code using multilinefile tag name… Please, check it before going on production: I was not able to test in a working website.
New version will support “Multifile Upload Field for Contact Form 7”.
You may remove your custom code to avoid future problems.
Hi I tried, I am getting data like this no urls
{ “text”: “*New message!*\n\nan\nj\[email protected]\nGreece (\u0395\u03bb\u03bb\u03ac\u03b4\u03b1)\n6912345678\n[“01\/90bc0c906fc30587b4863d0e6089f364-removebg-preview-13.png”,”01\/Vinayaka-24-13.png”,”01\/lord-ganesha-vector-34-10.png”,”01\/Super-store-offer-flyer-Made-with-PosterMyWall-11.jpg”]” }
and I am sorry, I mentioned wrong plugin
plugin name: Drag and Drop Multiple File Upload – Contact Form 7