Skip to content

curl_getinfo($ch, CURLINFO_CONTENT_TYPE) returns false when Content-Type header is not set #16929

Open
@ondrejcech

Description

@ondrejcech

Description

The following code:

<?php
$ch = curl_init();
$url = 'https://epapucs.hu/wp-content/uploads/2024/11/F318482161_2.webp';

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $url);
curl_exec($ch);

$ct = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);

var_dump($ct);

$info = curl_getinfo($ch)['content_type'];

var_dump($info);

curl_close($ch);

Resulted in this output:

bool(false)
NULL

I'd expect these two values to be the same. It's hard to handle errors when a false value is returned when there's no error.

These are the first elements of curl_getinfo associative_array:

array(41) {
  ["url"]=>
  string(63) "https://epapucs.hu/wp-content/uploads/2024/11/F318482161_2.webp"
  ["content_type"]=>
  NULL
  ["http_code"]=>
  int(200)

PHP Version

PHP 8.4.1

Operating System

macOS 15.1

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions