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

use*_*255 6 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);
}
Run Code Online (Sandbox Code Playgroud)

我收到了这个通知:

注意:file_get_contents():未指定Content-type假设在第17行的C:\ WebServer\Apache24\Apache24\htdocs\html\www\SocialNetwork\my-account.php中的application/x-www-form-urlencoded

虽然这不会破坏我的应用程序,但这很烦人.我该如何解决?

我试图在标题部分添加"User-Agent:MyAgent/1.0\r \n"和"Connection:close"但它似乎没有修复它!

Dan*_*scu 8

尝试将options数组替换为:

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