capture images remotely with PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • artlover70@yahoo.com

    capture images remotely with PHP

    Hi everyone !

    I am just wondering if capturing an image remotely with php is
    doable ?

    I am working on a project for my department where I need to write php
    code to capture an remote image and save it to a local folder/web site
    directory given an image's URL.

    Have anyone done anything like this ? If you have, do you mind share
    your ideas/sample code ?

    Thank you in advance,

    Josh

  • =?iso-8859-1?Q?Kim_Andr=E9_Aker=F8?=

    #2
    Re: capture images remotely with PHP

    artlover70@yaho o.com wrote:
    Hi everyone !
    >
    I am just wondering if capturing an image remotely with php is
    doable ?
    >
    I am working on a project for my department where I need to write php
    code to capture an remote image and save it to a local folder/web site
    directory given an image's URL.
    >
    Have anyone done anything like this ? If you have, do you mind share
    your ideas/sample code ?
    This will work in PHP 4.3.0 and above, and if allow_url_fopen is
    enabled:

    <?php
    $img = imagecreatefrom jpeg("http://example.com/path/to/image.jpg");
    imagejpeg($img, "localimage.jpg ");
    ?>

    Alternately, if image functions are disabled, this might work:

    <?php
    $imagedata = file_get_conten ts("http://example.com/path/to/image.jpg");
    $newfile = fopen("localima ge.jpg", "w");
    fwrite($newfile , $imagedata);
    fclose($newfile );
    ?>

    --
    Kim André Akerø
    - kimandre@NOSPAM betadome.com
    (remove NOSPAM to contact me directly)

    Comment

    • Carl

      #3
      Re: capture images remotely with PHP

      On Feb 2, 4:05 pm, artlove...@yaho o.com wrote:
      Hi everyone !
      >
      I am just wondering if capturing an image remotely with php is
      doable ?
      >
      I am working on a project for my department where I need to write php
      code to capture an remote image and save it to a local folder/web site
      directory given an image's URL.
      >
      Have anyone done anything like this ? If you have, do you mind share
      your ideas/sample code ?
      >
      Thank you in advance,
      >
      Josh

      If by "capturing an image remotely" you mean download and image from
      another website and store it locally, you have a couple of options.
      Both of these can be very simple depending on the configuration of
      your php installation.

      1. If allow_url_fopen is enabled on your machine, you can simply use
      fopen to download the image, and use the resulting file handle to copy
      the data to wherever you wish.
      http://www.php.net/fopen : see the comment made on '22-Jan-2007
      02:34', which, If i understood you correctly, does exactly what you
      want.

      2. Slightly more complex, but if your php installation supports curl
      you can simply use curl to fetch the remote data.


      Carl.

      Comment

      • artlover70@yahoo.com

        #4
        Re: capture images remotely with PHP

        Thank you all so much for your helpful tips and directions.

        Jay

        On Feb 2, 4:44 pm, "Carl" <c.gro...@gmail .comwrote:
        On Feb 2, 4:05 pm, artlove...@yaho o.com wrote:
        >
        Hi everyone !
        >
        I am just wondering if capturing an image remotely with php is
        doable ?
        >
        I am working on a project for my department where I need to write php
        code to capture anremoteimage and save it to a local folder/web site
        directory given an image's URL.
        >
        Have anyone done anything like this ? If you have, do you mind share
        your ideas/sample code ?
        >
        Thank you in advance,
        >
        Josh
        >
        If by "capturing an image remotely" you mean download and image from
        another website and store it locally, you have a couple of options.
        Both of these can be very simple depending on the configuration of
        your php installation.
        >
        1. If allow_url_fopen is enabled on your machine, you can simply use
        fopen to download the image, and use the resulting file handle to copy
        the data to wherever you wish.http://www.php.net/fopen: see the comment made on '22-Jan-2007
        02:34', which, If i understood you correctly, does exactly what you
        want.
        >
        2. Slightly more complex, but if your php installation supports curl
        you can simply use curl to fetch theremotedata.http://www.php.net/curl
        >
        Carl.

        Comment

        Working...