php - 文件获取内容(): Content-type not specified assuming application/x-www-form-urlencoded with imgur API

标签 php file-upload file-get-contents

我正在尝试创建一个应用程序来将个人资料图片上传到 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);
}

我收到这条通知:

Notice: file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded in C:\WebServer\Apache24\Apache24\htdocs\html\www\SocialNetwork\my-account.php on line 17

尽管这不会破坏我的应用程序,但它很烦人。我该如何解决?

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

最佳答案

尝试将选项数组替换为:

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

关于php - 文件获取内容(): Content-type not specified assuming application/x-www-form-urlencoded with imgur API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42353729/

相关文章:

javascript - 保存新的 div 顺序避免重复 sql 查询

iOS 7后台上传和POST请求

asp.net - Valums 文件 uploader xhr 返回状态 0、readystate 4 和 responseText 为空

javascript - 使用上传的 XML 文件填充 HTML5 输入字段

php - 替换在文本文件中找到特定单词的整行

php - Laravel - 向 Mailgun 发送电子邮件时出现 404 未找到错误

php - 备份MySql数据库?

php - simplexml_load_file 不工作

PHP - 假定应用程序/x-www-form-urlencoded 未指定内容类型

php - PHP 异常/错误处理库