【问题标题】:file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded with imgur APIfile_get_contents():假设应用程序/x-www-form-urlencoded 使用 imgur API 未指定内容类型
【发布时间】:2017-02-20 20:34:08
【问题描述】:

我正在尝试创建一个将个人资料图片上传到 imgur 的应用,但我遇到了问题。

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():假设内容类型未指定 应用程序/x-www-form-urlencoded in C:\WebServer\Apache24\Apache24\htdocs\html\www\SocialNetwork\my-account.php 第 17 行

即使这不会破坏我的应用程序,也很烦人。我该如何解决?

我尝试将“User-Agent:MyAgent/1.0\r\n”和“Connection: close”添加到标题部分,但似乎无法修复它!!!!

【问题讨论】:

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


    【解决方案1】:

    尝试将选项数组替换为:

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

    【讨论】:

    • 我不得不稍微更改您的代码,但最终它修复了它。谢谢:)
    • 工作,谢谢。似乎 Content-Type 必须是第一行,否则它不会识别。
    猜你喜欢
    • 1970-01-01
    • 2018-04-15
    • 2014-05-19
    • 1970-01-01
    • 2021-02-03
    • 2015-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多