无法使用dr chrono API通过php cURL上传pdf文档

xv8emn3q  于 2023-03-18  发布在  PHP
关注(0)|答案(1)|浏览(120)

我正在使用php curl在dr chrono中使用API/documents来上传pdf文档。实际上我不清楚如何传递我的pdf文件以便它被上传。
下面是我的params数组

$handle = fopen('pdfsPatientInformation_1446467593.pdf', 'r');
$myfile = fgets($handle);

$docParams = array('doctor' => 7891,'patient' => 58001561,'description' =>'Patient Medical History Form','date' => '2015-02-11','document' => $myfile);

我收到错误
{“文档”:[“提交的数据不是文件。请检查表单上的编码类型。"]}
请你帮我回答。

uhry853o

uhry853o1#

确保您使用“multipart/form-data”编码进行POST
使用PHP CURL:

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $THE_REMOTE_URL_YOU_ARE_POSTING_TO);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'document' => "@/Users/username/Desktop/test.pdf",
    'doctor' => "7891",
    'patient' => "58001561",
    'date' => "2015-11-02",
    'description' => "Patient Medical History Form"
  )); 
$response = curl_exec($ch);
?>

使用HTML:

<form method="post" enctype="multipart/form-data">
    <input type="text" name="doctor" value="7891">
    <input type="text" name="patient" value="58001561">
    <input type="text" name="description" value="Patient Medical History Form">
    <input type="text" name="date" value="2015-11-02">
    <input type="file" name="document">
    <input type="submit" name="submit" value="Upload">
</form>

或 curl :

curl -F "doctor=7891" -F "patient=58001561" -F "description=Patient Medical History" \
-F "date=2015-11-02" -F "document=@/Users/yourusername/Desktop/test.pdf" https://drchrono.com/api/endpoint/here

相关问题