【问题标题】:(Wordpress) Contact Form 7 - file_get_contents not working(Wordpress) 联系表 7 - file_get_contents 不工作
【发布时间】:2015-11-05 09:37:51
【问题描述】:

提交联系表格后,我会挂上提交。在联系表单上上传的文件需要发送到 SOAP 服务。为了接收文件数据,我执行以下操作:

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"])));
}

有什么想法吗?

【问题讨论】:

    标签: php wordpress file-get-contents


    【解决方案1】:

    好吧,这里没有太多魔法。上面的所有代码都正确。显然,您不能在 Contact Form 7 的挂钩中使用 file_get_contents。我将代码放在函数范围之外,并将数据文件放在会话变量中,这样我就可以在函数中使用它。

    长话短说:Contact Form 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
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-30
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 2016-07-17
      • 1970-01-01
      相关资源
      最近更新 更多