How to convert an image to base64 encoding?

前端 未结 9 1336
刺人心
刺人心 2020-11-22 06:01

Can you please guide me how can I convert an image from a URL to base64 encoding?

9条回答
  •  遇见更好的自我
    2020-11-22 06:42

    Here is an example using a cURL call.. This is better than the file_get_contents() function. Of course, use base64_encode()

    $url = "http://example.com";
    
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    ?>
    
      
    

提交回复
热议问题