After submission of the contact form I hook in on the submission. The file, uploaded on the contact form, need to be send to a SOAP service. In order to receive the filedata I do the following:
Returns empty:
$base64string = base64_encode(file_get_contents($_FILES["cv"]["tmp_name"]));
My $_FILES is not empty, so the file is in place. file_get_contents always returns an empty string. also, allow_url_fopen is on "On"
When I test this on a single PHP file (no Wordpress) it returns the BASE_64 string so it has to do something with Wordpress:
Working code:
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="cv">
<input type="submit" name="formsubmit">
</form>
<?
if(isset($_POST['formsubmit'])){
print_r(base64_encode(file_get_contents($_FILES["cv"]["tmp_name"])));
}
Any ideas?
Alright, not much magic going on here. All the code above is correct. Apparently you cannot use file_get_contents within the hook of Contact Form 7. I placed my code outside the scope of the function and put the datafile in a session variable, so I could use it in my function.
Long story short: no file_get_contents in Contact Form 7, put it outside the scope of the hook.
if(!empty($_FILES['cv'])){
$file = file_get_contents($_FILES["cv"]["tmp_name"]);
$_SESSION['filestring'] = $file;
}
function wpcf7_soap_service($contact_form) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
//Use session variable here
}
}