使用PHP curl在PHP 5.3.8上的zip文件上运行PUT命令

时间:2016-06-23 08:32:33

标签: php curl

您好我需要使用curl在PHP中执行此PUT命令,但是我遇到了运行它的问题。需要传输的文件是zip文件。这是curl命令:

curl -X PUT -H“Content-Type:application / zip”--data-binary @ yZip.zip http://183.262.144.266:1211/y-validation/repository/HELLO

这是我到目前为止的代码

$ch = curl_init();
$filepath = 'yZip.zip';
curl_setopt($ch, CURLOPT_URL, 'http://183.262.144.266:1211/y-validation/repository/HELLO');
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
$fh_res = fopen($filePath, 'r');
curl_setopt($ch, CURLOPT_INFILE, $fh_res);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($filePath));
curl_setopt($ch, CURLOPT_TIMEOUT, 86400); // 1 Day Timeout
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
$curl_response = curl_exec ($ch);
print_r($curl_response);

我从各种网站上获取此代码,但我一直收到错误,不知道接下来该做什么想法?

更新:修复了错误,我正在成功链接REST API但是zip文件没有正确上传。

更新2:更新了我自尝试解决问题后所做的代码更改但是zip仍未正确进行PUT。我也在使用PHP 5.3.8,所以不能使用CurlFile类。任何人都可以帮忙吗?

更新3:仍然遇到问题,尝试实施标题,但是那些不起作用也可以帮助我吗?

0 个答案:

没有答案