2013-04-26 136 views
0

我有以下代码将文件上传到Dropbox的上传文件到Dropbox的用PHP

 $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 
" 
+1

错误消息似乎很清楚 - 您需要检查您设置的Content-Type标头。 – andrewsi 2013-04-26 20:31:09

+0

@andrewsi感谢您的答案,但标题不包含错误消息中的类型! – 2013-04-26 20:44:04

+0

您是否尝试过[Dropbox_API](http://code.google.com/p/dropbox-php/wiki/Dropbox_API)for php? – 2013-04-26 20:45:01

回答

0

您需要添加:

curl_setopt($context, CURLOPT_HTTPHEADER, array('Content-type' => 'image/jpeg')); 

,并在适当的MIME类型填写。如果您需要确定该类型,请使用fileinfo