php - 我想在 wp 媒体文件夹中上传 PDF 文件并更新 ACF 字段
问题描述
我已经设置了 HTML 2 PDF 代码,并且我已经通过 html2pdfrocket API 添加了这个,当我运行这个 API 时,PDF 被下载,这可以,我希望 PDF 下载和上传也在 wordpress 媒体库中。
// Set parameters
$postdata = http_build_query(
array(
'apikey' => $apikey,
'value' => $value,
'MarginBottom' => '10',
'MarginLeft' => '10',
'MarginRight' => '10',
'MarginTop' => '10'
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
// Convert the HTML string to a PDF using those parameters
$result = file_get_contents('http://api.html2pdfrocket.com/pdf', false,
$context);
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . strlen($result));
header('Content-Disposition: attachment; filename=' . 'My CV.pdf' );
$results = file_get_contents("http://api.html2pdfrocket.com/pdf?apikey=" . urlencode($apikey) . "&value=" . urlencode($value));
update_field('pdf_file', 'sdsd', 'user_'.$current_user->ID);
echo $result; //echo result auto download PDF but i want upload also.
解决方案
推荐阅读
- c# - 使用 nullcheck 确定执行流程以尽可能最佳地操作组件
- javascript - 如何将反应组件状态从一个组件更新到另一个组件,并从任何组件调用任何函数
- java - 如何正确重启服务onResume
- reactjs - 通过filepond获取上传文件的blob
- javascript - 如何使用 JavaScript 延迟 JavaScript 函数调用
- javascript - Javascript 小游戏,球一次从球拍上反弹多次
- angular - 拒绝在 Angular App 中构建来自 AWS 的 PDF
- mosek - “mosek.dparam.optimizer_max_time”的时间单位?
- jakarta-mail - 如何通过 IMAP 将电子邮件正文与呈现的线程分开?
- java - 意外的标记: '
' 使用 hibernate、JPQL 和 postgres 函数时出错