简体   繁体   中英

file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded with imgur API

I'm trying to create an app to upload profile images to imgur but I'm having a problem.

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);
}

I'm getting this notice:

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

even though this doesn't break my app, it's annoying. How can I fix it?

I've tried to add "User-Agent:MyAgent/1.0\\r\\n", and "Connection: close" to the header part but it doesn't seem to fix it!!!!

Try replacing the options array with:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM