首页 > 解决方案 > 下面 curl 命令的 php curl 版本是什么

问题描述

以下命令的 php curl 版本是什么

curl -X PUT -H 'Content-Type: text/csv' -H 'Accept: application/json' -d @file.csv [URL]

我有以下 php curl 版本,它不起作用

$headers = [
   'Content-Type: text/csv',
   'Accept: application/json'
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($filename));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);

标签: phpcurlphp-curl

解决方案


试试下面的代码

$headers = [
   'Content-Type: text/csv',
   'Accept: application/json'
];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, ''.$url'');
curl_setopt($ch, CURLOPT_PUT, 1);

$fp = fopen($file_path, 'r');

curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file_path));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response= curl_exec ($ch);
fclose($fp);


推荐阅读