P粉3216766402023-09-01 00:09:52
嗨,您可以查看下面的答案,了解我是如何成功實現這一目標的。
// $source = file_get_contents("https://URL/assets/email_images/employee_manual3.pdf"); $file_path = __DIR__.'/../../../assets/email_images/employee_manual3.pdf'; // var_dump(__DIR__.'/../../../assets/email_images/employee_manual3.pdf'); // exit; // var_dump(new CURLFILE($file_path, 'application/pdf', 'file')); // exit; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'API URL', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('file' => new CURLFILE($file_path, 'application/pdf', 'file')), )); $response = curl_exec($curl); curl_close($curl); echo $response;