How to use PHP cURL to send images with the correct Content-Type?

前端 未结 1 1541
心在旅途
心在旅途 2020-12-11 08:27

Objective:

I want to send multiple images using multipart/form-data. Below is a snippet of my code.

Problem:

On on

相关标签:
1条回答
  • 2020-12-11 08:43

    Use the CURLOPT_HTTPHEADER option:

    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: image/jpeg"));
    

    So specify Content-Type headers specifically for file uploads, use:

    $params = array('name'=>'@D:\globe.jpg;type=image/jpeg');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    
    0 讨论(0)
提交回复
热议问题