我有以下代码将文件上传到Dropbox
$context = $this->createRequestContext($url, "PUT");
curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
$fh = fopen($src_file, 'rb');
curl_setopt($context,CURLOPT_HEADER,true);
curl_setopt($context, CURLOPT_INFILE, $fh); // file pointer
curl_setopt($context, CURLOPT_INFILESIZE, filesize($src_file));
$context = $this->createRequestContext($url, "PUT", $content);
$meta = json_decode(self::execCurlAndClose($context));
fclose($fh);
return $meta;
我的问题是每次我得到以下错误作为回复:
["error"]=> string(121) "Upload failed. Content-Type must not be empty and not one of ('application/x-www-form-urlencoded', 'multipart/form-data')"
我正在尝试上传任何类型的文件,但将来我只想上传pdf文件。你能帮我说明我做错了吗?
这是标题:
["method"]=>
string(3) "PUT"
["header"]=>
string(64) "Content-Length: 230783
Content-Type: application/octet-stream
"
答案 0 :(得分:0)
您需要添加:
curl_setopt($context, CURLOPT_HTTPHEADER, array('Content-type' => 'image/jpeg'));
并填写适当的mimetype。如果您需要确定该类型,请使用fileinfo