Retrieving/dumping image from another site

Discussion in 'PHP' started by aliweb, May 7, 2010.

  1. #1
    Hi,

    How can I retrieve/dump images from another site using PHP?
    For e.g. if this is the URL

    www.digitalpoint.com/image.jpg

    Then how can I save this image on my server using PHP. Can this be done using Snoopy class?

    Thanks
     
    aliweb, May 7, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Theirs many ways, fsockopen(), cURL and file_get_contents().

    <?php
    //image url... - ensure it starts with http:// and exists...
    $url = 'http://www.digitalpoint.com/image.jpg';
    file_put_contents(basename($url), file_get_contents($url));
    ?>
    PHP:
    That will save image.jpg to your server (within __DIR__)
     
    danx10, May 7, 2010 IP
  3. aliweb

    aliweb Well-Known Member

    Messages:
    250
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #3
    Thanks!!
    This is exactly I was looking for.
     
    aliweb, May 7, 2010 IP