How can you automatically assign the file type when loading files with curl in PHP?

When loading files with curl in PHP, you can automatically assign the file type by setting the appropriate Content-Type header in the curl request. This can be done by using the CURLOPT_HTTPHEADER option and specifying the Content-Type header value based on the file type being loaded. By setting the Content-Type header, you inform the server about the type of data being sent, allowing it to handle the file correctly.

$url = 'https://example.com/file.jpg';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: image/jpeg']);
$response = curl_exec($ch);
curl_close($ch);

// Process the response data as needed