How to save a file from an URL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Timin Uram

    How to save a file from an URL

    Can someone tell me how to write php code to save an image from the
    internet to the server? For example, if there was a picture at
    http://somepage.com/hello.jpg I want to write a php script that would
    take that picture and save it to my server so I could access it as
    http://localhost/hello.jpg.

    I need to do this in php because there are a lot of these pictures and
    I want to save all of them at once.

    Thanks for your help!
    Timin

  • ZeldorBlat

    #2
    Re: How to save a file from an URL

    <?
    //set to the URL of the file you want to download:
    $inPath = "http://somepage.com/hello.jpg";
    //set to the local path where the file should be saved:
    $outPath = "/usr/local/htdocs/hello.jpg";

    $in = fopen($inPath, "rb");
    $out = fopen($outPath, "wb");

    while ($chunk = fread($in,8192) ) {
    fwrite($out, $chunk, 8192);
    }

    fclose($in);
    fclose($out);
    ?>

    Comment

    • Chung Leong

      #3
      Re: How to save a file from an URL


      "Timin Uram" <somenimit@hotm ail.com> wrote in message
      news:1113095100 .300042.167860@ g14g2000cwa.goo glegroups.com.. .[color=blue]
      > Can someone tell me how to write php code to save an image from the
      > internet to the server? For example, if there was a picture at
      > http://somepage.com/hello.jpg I want to write a php script that would
      > take that picture and save it to my server so I could access it as
      > http://localhost/hello.jpg.
      >
      > I need to do this in php because there are a lot of these pictures and
      > I want to save all of them at once.
      >
      > Thanks for your help!
      > Timin
      >[/color]




      Comment

      Working...