I cant save some facebook images to my server as it does not understand the file

后端 未结 2 1295
长情又很酷
长情又很酷 2021-01-17 04:26

I am using the facebook graph api and it was working well until I realised that some of the jpg files have a query string at the end that is making them unusable.

e.

相关标签:
2条回答
  • 2021-01-17 04:51

    You could always download the image using file_get_contents()

    This code works for me...

    file_put_contents("image.jpg", file_get_contents("https://scontent.xx.fbcdn.net/hphotos-xaf1/v/t1.0-9/522827_10152235166655545_26514444_n.jpg?oh=1d52a86082c7904da8f12920e28d3687&oe=5659D5BB"));
    
    0 讨论(0)
  • 2021-01-17 04:53

    Just because something has .jpg in the URI doesn't mean it's an image.

    Getting that URL via wget gives the result:

    <!DOCTYPE html>
    <html lang="en" id="facebook">
      <head>
        <title>Facebook | Error</title>
        <meta charset="utf-8">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="cache-control" content="no-store">
        <meta http-equiv="cache-control" content="max-age=0">
        <meta http-equiv="expires" content="-1">
        <meta http-equiv="pragma" content="no-cache">
        <meta name="robots" content="noindex,nofollow">
        <style>
        ....
        ....
    

    i.e. it's not an image, exactly as the error message is telling you.

    0 讨论(0)
提交回复
热议问题