Good morning, I’m writing some php strings in fuction.php. This code get specific details of formv(CF7) and write its in a txt file in ftp. I done all fields but I’m not able get the url of uploaded file. I have to get url and write it toghether other fields in txt file. How I can do it?
I tried with:
$text .= $data['file-799'];
but it doesnt work
This is the code:
add_action('wpcf7_before_send_mail', 'log_cf7');
function log_cf7($WPCF7_ContactForm) {
$submission = WPCF7_Submission::get_instance();
$data = $submission->get_posted_data();
$upload_dir = wp_upload_dir();
echo $upload_dir['basedir'] . '/wpcf7_uploads';
$text .= "|";
$text .= "CSTPRODREG";
$text .= "||||||||||||||||";
$text .= $data['checkbox-339'];
$text .= "||";
$text .= $data['your-name'];
$text .= "|";
$text .= $data['text-628'];
$text .= "||||||";
$text .= $data['tel-709'];
$text .= "|||";
$text .= $data['your-email'];
$text .= "|||||";
$text .= $data['menu-470'][0];
$text .= "||";
$text .= $data['menu-749'][0];
$text .= $data['menu-750'][0];
$text .= $data['menu-751'][0];
$text .= $data['menu-752'][0];
$text .= $data['menu-753'][0];
$text .= "||";
$text .= $data['text-590'];
$text .= $data['text-591'];
$text .= "||";
$text .= $formatted_date = str_replace('-', '', $data['date-855']);
$text .= "|||";
// follow the field of form for uploaded file
$text .= $data['file-799'];
foreach ($data as $key => $value) {
}
$myfile = fopen($_SERVER['DOCUMENT_ROOT'] . "/myfile.txt","wb");
fwrite($myfile, $text);
$ftp_server="myserver";
$ftp_username="myuser";
$ftp_userpass="mypass";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
if(ftp_put($ftp_conn,"newdata.prr",$_SERVER['DOCUMENT_ROOT'] . "/myfile.txt",FTP_ASCII))
{
print("yay");
}
else
{
print("f...");
}
fclose($myfile);
}
?>
Thanks in advance
2
Answers
The answer often are more easy that we are thinking... Since cf7 with Contact Form CFDB7 record every file submissioned in a ftp folder I only wrote this string:
And in this way, whit the other necessary fields, function.php write in txt file the complete url of uploaded file
thank you all
I think CF7 stores uploaded files in a temporary location and attaches them to the email as attachments. It doesn’t provide a direct URL to the uploaded file by default. To get the URL of the uploaded file, you can modify your code as follows: