【问题标题】:PHP / Using a class to download a .vcf filePHP / 使用类下载 .vcf 文件
【发布时间】:2017-09-12 16:47:12
【问题描述】:

今天我需要这个表格的帮助。它将以.vcf 格式将数据保存在vcard 中,并且此表单位于html 页面中,我无法提交到另一个页面。所以现在,如果我点击保存按钮,它会以 .vcf 扩展名正确下载,但文件中有整个 html 页面......我只需要下载 vcard,我使用的是从这里https://github.com/facine/vCard/blob/master/vCard.class.php 检索的类。 也许使用 simple_html_dom.php 我可以提取我需要的 div ...... 感谢您的帮助!

<form method="post" action="#">
<button name="btn_func" class="btn waves-effect waves-light red">
 <span class="white-text">Salva nella rubrica</i></span>
</button>
<div id="savecard">
<?php 
 include('simple_html_dom.php');                        
 include('vcard.php');
 $card = new vCard();
 $card->setnew("first_name", $params['user']->first_name);
 $card->setnew("last_name", $params['user']->last_name);
 $card->setnew("birthdate", $params['user']->birthdate);
 $card->setnew("home_address", $params['user']->address);
 if(isset($_POST['btn_func'])){
 $card->download();
 }
 ?>
 </div></form>

【问题讨论】:

    标签: php forms submit


    【解决方案1】:

    只需在您的 PHP 代码中添加标头即可。

    <form method="post" action="#">
    <button name="btn_func" class="btn waves-effect waves-light red">
     <span class="white-text">Salva nella rubrica</i></span>
    </button>
    <div id="savecard">
    <?php 
     include('simple_html_dom.php');                        
     include('vcard.php');
     $card = new vCard();
     $card->setnew("first_name", $params['user']->first_name);
     $card->setnew("last_name", $params['user']->last_name);
     $card->setnew("birthdate", $params['user']->birthdate);
     $card->setnew("home_address", $params['user']->address);
     if(isset($_POST['btn_func'])){
    header('Content-Type: text/x-vcard');
     $card->download();
     }
     ?>
     </div></form>
    

    希望对你有所帮助..

    【讨论】:

    • 那么您从哪里检索数据库中的用户详细信息?
    • 来自变量,但这不是问题。 .vcf 文件里面有所有的 html 代码和 vcard 的正确代码,我只需要这个没有所有的 html 代码。
    猜你喜欢
    • 2011-05-26
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 2017-07-19
    • 2022-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多