dtt78245 2017-02-16 11:01
浏览 114

PUT上传php curl命令响应为“Missing Content-Length header”。

I write a php script to upload a media file but when I use it the response occurs:

Missing Content-Length header.

The php code is:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://raz-ul.domenka.com/v1/AUTH_8a619275-f933-4da1-b289-0ca1a2a3a4a5/bcd/drop1.avi");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

$headers = array();
$headers[] = "X-Auth-Token: AUTH_tkd78bedda5bec4613b80becb1b2b3b4b5";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

$header_size  = $info['header_size'];
$header       = substr($response, 0, $header_size);

var_dump($header);

On the other hand When I do something like that in cli I succeed:

kinduser@43915-1-c1c2c3-01:~/public_html/adam$ curl -i -X PUT -H "X-Auth-Token: AUTH_tkd78bedda5bec4613b80bec0123456789" -T drop.avi https://raz-ul.domenka.com/v1/AUTH_8a619275-f933-4da1-b289-0ca1a2a3a4a5/bcd/drop.avi
HTTP/1.1 100 Continue

HTTP/1.1 201 Created
Last-Modified: Thu, 16 Feb 2017 10:12:54 GMT
Content-Length: 0
Etag: fa60ba1b78299bfae5ac61d1d2d3d4d5
Content-Type: text/html; charset=UTF-8
X-Trans-Id: tx114b22027223415c850db-e1e2e3e4e5
Date: Thu, 16 Feb 2017 10:12:53 GMT

kinduser@43915-1-c1c2c3-01:~/public_html/adam$

But I would like to do this in php. How to fix my php code?

Update I added some code to tell curl which file to send. It sent the file but the file changed on the server. It got a bigger weight from 660kB to 660.31kB. After downloading to my pc it got impossible to open via video player.

That code is like this now:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://raz-ul.domenka.com/v1/AUTH_8a619275-f933-4da1-b289-0ca1a2a3a4a5/bcd/drop7.avi");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

$headers = array();
$headers[] = "X-Auth-Token: AUTH_tkd78bedda5bec4613b80becb1b2b3b4b5";

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$curlFile = curl_file_create ('./drop.avi');

$post = array (
    'extra_info' => '123456',
    'file_contents' => $curlFile
);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);


$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

$header_size  = $info['header_size'];
$header       = substr($response, 0, $header_size);

var_dump($header);

Any idea how to fix it?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算