How to save a file from an URL

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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 I want to write a php script that would
take that picture and save it to my server so I could access it as

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!

Re: How to save a file from an URL

//set to the URL of the file you want to download:
$inPath = "";
//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);


Re: How to save a file from an URL

Quoted text here. Click to load it /

Site Timeline