file_get_contents():假设application / x-www-form-urlencoded with imgur API,未指定Content-type

时间:2017-02-20 20:34:08

标签: php file-upload file-get-contents

我试图创建一个应用程序来上传个人资料图片,但我遇到了问题。

if (isset($_POST['uploadprofileimg'])) {
   $image = base64_encode(file_get_contents($_FILES['profileimg']['tmp_name']));

   $options = array('http' => array(
       'method' => "POST",
       'header' => "Authorization: Bearer sdf541gs6df51gsd1bsb16etb16teg1etr1ge61g\n",
       "Content-Type: application/x-www-form-urlencoded",
       'content' => $image
   ));

   $context = stream_context_create($options);

   $imgurURL = "https://api.imgur.com/3/image";

   $response = file_get_contents($imgurURL, FALSE, $context);
}

我收到此通知:

  

注意:file_get_contents():未指定内容类型   application / x-www-form-urlencoded in   C:\ Web服务器\ Apache24 \ Apache24 \ htdocs中\ HTML \ WWW \ SocialNetwork \ MY-account.php   第17行

虽然这并没有打破我的应用程序,但它很烦人。我该如何解决?

我尝试添加"用户代理:MyAgent / 1.0 \ r \ n"和"连接:关闭"到标题部分,但它似乎没有解决它!!!!

1 个答案:

答案 0 :(得分:6)

尝试用以下选项替换options数组:

$options = array('http' => array(
    'method' => "POST",
    'header' =>
        "Content-Type: application/x-www-form-urlencoded\r\n".
        "Authorization: Bearer sdf541gs6df51gsd1bsb16etb16teg1etr1ge61g\n",
    'content' => $image
));