How to base64 encode an image from the facebook api

后端 未结 4 1588
北恋
北恋 2021-01-23 06:21

I am attempting to convert an image url provided by the facebook api into base64 format with cURL.

the api provides a url as such:

https://fbcdn-sphotos-         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-23 07:14

    To address your specific problem, your script is likely failing because the required oh, oe, __gda__ parameters are getting separated during the GET request and therefore are not included in $_GET['url'].

    Make sure you're using a URL-encoded string so any unencoded & characters aren't handled as delimiters. Then just decode the string before passing it on to cURL.

    ...
    
    $url = urldecode($_GET['url']);
    
    ...
    

    For anyone curious, you can still load any Facebook image from any one of their legacy CDNs without needing the new parameters:

    1. https://scontent-a-iad.xx.fbcdn.net/hphotos-frc3/
    2. https://scontent-b-iad.xx.fbcdn.net/hphotos-frc3/
    3. https://scontent-c-iad.xx.fbcdn.net/hphotos-frc3/

    Just append the original image filename to the URL et voila.

    Disclaimer: I have no idea how long this little trick will work for so don't use it on anything important in production.

提交回复
热议问题