2015-11-05 76 views
0

在提交聯繫表格我提交後掛鉤。上傳到聯繫人表單中的文件需要發送到SOAP服務。爲了收到filedata我做到以下幾點:(WordPress的)聯繫表7 - file_get_contents不起作用

Returns empty: 
$base64string = base64_encode(file_get_contents($_FILES["cv"]["tmp_name"])); 

我的$ _FILES不是空的,所以文件就位。 file_get_contents 總是返回一個空字符串。同時,allow_url_fopen選項是「開」

當我測試這一個單一的PHP文件(沒有WordPress的),它返回的字符串BASE_64所以它必須做一些事情的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"]))); 
} 

任何想法?

回答

0

好吧,這裏沒有太多的魔法。以上所有代碼均爲正確。顯然,你不能在聯繫表單7的鉤子中使用file_get_contents。我把我的代碼放在函數的作用域之外,並把數據文件放在一個會話變量中,這樣我就可以在我的函數中使用它。

長話短說:在聯繫表單7中沒有file_get_contents,把它放在鉤子的範圍之外。

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 
    } 
}